3

如何减小 indexsearcher.search() 函数返回的“Hits”对象的大小?

目前我做类似的事情:

Hits hits = indexSearch.search(query,filter,...);

Iterator hitsIt = hits.iterator();
int newSize=0;
while (hitsIt.hasNext()){
   Hit currHit = (Hit)hitsIt.next();

   if (hasPermission(currHit)){
      newSize++;
   }
}

但是,当点击数很大(如 500 或更多)时,这会产生巨大的性能问题。

我听说过一种叫做“HitsCollector”或“Collector”的东西,它应该有助于提高性能,但我不知道如何使用它。

如果有人能指出我正确的方向,将不胜感激。

我们正在使用 Apache Lucene 在 Atlassian Confluence Web 应用程序中进行索引。

4

2 回答 2

2

收集器只是一个简单的回调机制,每个文档命中都会调用它,您可以使用这样的收集器:-

public class MyCollector extends HitCollector {

// this is called back for every document that 
// matches, with the docid and the score

public void collect(int doc, float score){

    // do whatever you have to in here

}
}

..

HitCollector collector = new MyCollector();

indexSearch(query,filter,collector);
于 2012-07-14T22:12:25.530 回答
1

为了获得良好的性能,您必须将安全信息与每个文档一起编入索引。这当然取决于您的安全模型。例如,如果您可以将每个文档分配给对其具有权限的安全角色,那么就使用它。也看看这个问题。你的几乎是那个的副本。

于 2012-03-30T11:10:23.797 回答