2

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

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

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

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

提前致谢 :)

4

2 回答 2

0

好的,为了测试,我有 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];

谢谢

于 2012-07-19T14:39:18.583 回答
0

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

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

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

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

您能否向我们展示您如何填充/查询您的索引?

于 2012-07-19T11:29:58.667 回答