[ 
https://issues.apache.org/jira/browse/LUCENE-5795?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14049701#comment-14049701
 ] 

Simon Willnauer commented on LUCENE-5795:
-----------------------------------------

I think making the priority queue bounded makes perfect sense. Yet, I think 
when we touch this queue we should also make sure we get rid of the crazy 
Object[] that is holds. We should really add a struct like object that holds 
the individual values rather than an Object array that requires Float rather 
than float (we should prefer the latter). 
Further I think if we really want to make this more efficient we (not sure 
about the O(n) though but that's a different story) we should not use 

{code}
      res.insertWithOverflow(new Object[]{word, // the word
          topField, // the top field
          score,// overall score
          idf, // idf
          docFreq, // freq in all docs
          tf
      });
{code}

it will add the element no matter if we exceed the size of the queue or not.

we should rather do something like:

{code}
final int limit = Math.min(maxQueryTerms, words.size());
//...

if (queue.size() < limit) {
  // there is still space in the queue
  queue.add(new ScoreTerm(word, topField, score, ...))
} else {
  ScoreTerm term = queue.top();
  if (term.score() < score) { // update the smallest in the queue in place and 
update the queue.
    term.update(word, topField, score, ...);
    queue.updateTop();
  }
} 
{code}

I hope that makes sense?

> More Like This: ensures selection of best terms is indeed O(n)
> --------------------------------------------------------------
>
>                 Key: LUCENE-5795
>                 URL: https://issues.apache.org/jira/browse/LUCENE-5795
>             Project: Lucene - Core
>          Issue Type: Improvement
>            Reporter: Alex Ksikes
>            Priority: Minor
>         Attachments: LUCENE-5795
>
>




--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to