8

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.

Community
  • 1
  • 1
Richi
  • 89
  • 2
  • You're not using the raw Lucene API, though, you're using Compass. Are you sure Compass is displaying the same behaviour? – skaffman Nov 16 '10 at 09:59
  • Yes im sure I checked it – Richi Nov 16 '10 at 10:18
  • That just implies compass is way behind. Hits was removed in Lucene 3. You normally use a collector of your own and specify a "guess" as to the maximum number you want. – MJB Apr 30 '11 at 20:21
  • @MJB: Compass is still based on Lucene 2.9.x, and is now in maintenance mode. The author has moved on to other projects. – skaffman May 11 '11 at 16:15
  • Even so, the deprecation of hits took place in Lucene 2.3 or 2.4.... – MJB May 11 '11 at 19:02

1 Answers1

2

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

MJB
  • 9,352
  • 6
  • 34
  • 49