Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compass Lucene hits

I use Lucene and Compass on it and I have a problem:

          try {
      
       CompassHits hits = compassQuery.hits();
       for (CompassHit compassHit : hits) {
        if (results.size() >= maxResults) {
         Log.info(this, "Number of results exceeded %,d for query %s", maxResults, query);
         break;
        } else {
    
         results.add((T) compassHit.getData());
        }
       }
       

  } 

When the data is geting by compassHit.getData()); and it's a 100 hit it re-execute the search, is there any possibility to change it to 200 or more?

EDIT:

From wiki apache org:

"Iterating over all hits is slow for two reasons. Firstly, the search() method that returns a Hits object re-executes the search internally when you need more than 100 hits".

And my question is there opportunity to change this value "100" to "200"? but important is that I use compass nor a raw Lucene.

like image 612
Richi Avatar asked Nov 15 '10 16:11

Richi


1 Answers

I looked at the source for Hits in 2.9.2. It's hard coded. It looks like it's hard coded

 Hits(Searcher s, Query q, Filter f) throws IOException {
    this.weight = q.weight(s);
    this.searcher = s;
    this.filter = f;
    this.nDeletions = countDeletions(s);
    getMoreDocs(50);
    this.lengthAtStart = this.length;
  }

If you weren't using Compass, you could follow the instructions in the JavaDoc for Hits which suggests a replacement

Instead e. g. TopDocCollector and TopDocs can be used:

  TopDocCollector collector = new TopDocCollector(hitsPerPage);
   searcher.search(query, collector);
   ScoreDoc[] hits = collector.topDocs().scoreDocs;
   for (int i = 0; i < hits.length; i++) {
     int docId = hits[i].doc;
     Document d = searcher.doc(docId);
     // do something with current hit
     ...

But since you are, unless you are willing to rewrite part of Compass, I think you are stuck

like image 115
MJB Avatar answered Oct 19 '22 15:10

MJB