user1068636
user1068636

Reputation: 1939

How to filter out "Hits" result returned by indexsearcher.search() function?

How can I reduce the size of a "Hits" object that is returned by indexsearcher.search() function?

Currently I do something like:

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++;
   }
}

However, this is creating a huge performance problem when the number of hits is large (like 500 or more).

I have heard of something called "HitsCollector" or maybe "Collector" which is supposed to help improve performance, but I don't have any idea how to use it.

Would appreciate it if someone could point me in the right direction.

We are using Apache Lucene for indexing within the Atlassian Confluence web application.

Upvotes: 3

Views: 215

Answers (2)

solidfox
solidfox

Reputation: 571

A Collector is just a simple callback mechanism that gets invoked for each document hit, you'd use a collector like this :-

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);

Upvotes: 2

Marko Topolnik
Marko Topolnik

Reputation: 200138

For good performance you will have to index you security information along with each document. This of course depends on your security model. For example, if you can assign each document to security roles that have permissions for it, then use that. Also check out this question. Yours is pretty much a duplicate of that.

Upvotes: 1

Related Questions