【问题标题】:lucene search in iOS inconsistentiOS中的lucene搜索不一致
【发布时间】:2012-07-14 12:06:02
【问题描述】:

我正在尝试改进 iOS 应用程序的搜索算法,该应用程序提供一些包含大量文章的杂志。为此,我使用了 Micheal Papp (git repo) 的 S4LuceneLibrary,它是一个等效于 Apache Lucene 的全功能文本搜索引擎库的 iOS。 问题是,现在的搜索非常不一致……这意味着对特定单词的搜索有时需要很长时间,而另一方面有时不需要。

这是我正在搜索的单词列表,以及搜索所用的时间:

  • 柏林(34 次点击)-> 3.5 秒
  • 标记(29 次点击)-> 8.3 秒
  • 豪斯(3 次点击)-> 3.6 秒
  • Straße(28 次点击)-> 8 秒
  • Raumfahrt(5 次点击)-> 6.2 秒
  • 天文学(9 次点击)-> 1 秒

所以结果有点不同,但我认为每个搜索短语都应该花费相同的时间。你知道区别在哪里吗?

提前致谢:)

【问题讨论】:

  • 这些响应时间非常长,尤其是对于简单的术语查询...我不敢相信在库代码或客户端代码中没有真正的错误。虽然对 Lucene 很熟悉,但对 iOS 却一点也不熟悉。 iOS 上是否有任何可用的分析工具可以帮助您找到瓶颈?
  • 是的,它们有点高,但如果你比较时间,它们的差异最大因子为 8,这让我感到困惑。所以“Astronomie”这个词只需要 1 秒,而“Tag”这样的词则需要 8 多秒。这是为什么呢?

标签: ios search lucene


【解决方案1】:

哇,这些基准!你的索引/收藏有多大?

我在这里假设,您正在以编程方式搜索索引? (而不是通过一些复杂的实现/UI,这可能有其自身的故障)

我的首要任务是确保您首先正确索引您的收藏。特别是:检查您在每个文档中放置的字段的构造函数。某些形式的构造函数对“store”和“index”使用布尔值:确保你已经传递了它:store.yesindex.yes 在这种情况下,否则它们将在那里并且可以检索,但不能通过 lucene 的倒置index - 整个工具的关键。

但是,鉴于您的集合的大小可能没有变化,如果是这种情况,那么您的搜索时间就会大不相同,这很奇怪。

您能告诉我们您如何填充/查询您的索引吗?

【讨论】:

    【解决方案2】:

    好的,为了测试,我有 6 个杂志,每个杂志都有自己的索引。所以索引大小是:

    434kb、41kb、139kb、434kb、57kb 和 57kb

    我的索引代码是:

    LCSimpleAnalyzer *analyzer = [[LCSimpleAnalyzeralloc] init];
        LCIndexWriter *writer = [[LCIndexWriteralloc] initWithDirectory:[selfcreateFileDirectoryWithEmagPath:emagModel.emagPath] analyzer: analyzer create: YES];
    
    ...
    // creating searchResult
    ...
    
    // adding relevant information to lucene document
    LCDocument *doc = [[LCDocumentalloc] init];
    
    LCField *fieldContent = [[LCFieldalloc] initWithName: @"content_to_search"string:bodyText store:LCStore_YES index:LCIndex_Tokenized];   
    LCField *fieldResult = [[LCFieldalloc] initWithName:@"data" data: [NSKeyedArchiverarchivedDataWithRootObject:result] store:LCStore_YES];
    
    [doc addField:fieldContent];
    [doc addField:fieldResult];  
    
    [writer addDocument:doc];
    
    ...
    // releasing stuff and close writer
    

    这就是搜索的代码:

    // search
    LCIndexSearcher *searcher = [[LCIndexSearcheralloc] initWithDirectory: [selfgetFileDirectoryOfEmagPath:emagPath]];
    LCTerm *term = [[LCTermalloc] initWithField: @"content_to_search" text: self.searchText];
    LCTermQuery *termQuery = [[LCTermQueryalloc] initWithTerm:term];
    
    LCHits *hits = [searcher search:termQuery];
    

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-25
      • 1970-01-01
      • 2012-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-23
      相关资源
      最近更新 更多