You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by gabriele renzi <rf...@gmail.com> on 2010/03/05 10:13:52 UTC

DisjunctionMaxQuery and custom Sort

Hi everyone,

In our search app we'd perform searches with a DisjunctionMaxQuery
with code like

  searcher.search(query, hits)

Now we'd like to add a custom sub-sort so that when the search returns
two documents with the same score they will be ordered by a custom
field (this is not a boost for two reasons: first,  we already use
boosting for other goals, second, we may like to add a third level of
boosting in the future)

I thought I could just change the former line to something like

  searcher.search(query, null, hits, new Sort(SortField.SCORE_FIELD,
new CustomSortField())

but I had unexpected results, so I dropped our custom SortField, and
tried the simple

  searcher.search(query, null, hits, new Sort(SortField.SCORE_FIELD))

which I though should have the same behaviour of our original code:
yet, a large part of our tests failed because it appears that the
results are not the same as above.

So my question is threefold:
1. is the last query really not functionally equivalent to the first?
2. if not, how would the equivalent be?
3. and how can I perform a sub-sorting of the results by relevance
first and my custom score field later?

FWIW I am using lucene 2.9.1, java 1.6, OSX 10.6. Thanks in advance
for any help.

-- 
blog en: http://www.riffraff.info
blog it: http://riffraff.blogsome.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: DisjunctionMaxQuery and custom Sort

Posted by gabriele renzi <rf...@gmail.com>.
On Fri, Mar 5, 2010 at 10:42 AM, Ian Lea <ia...@gmail.com> wrote:
> From the javadocs for the search with sort method it appears you are calling:
>
> NOTE: this does not compute scores by default; use
> IndexSearcher.setDefaultFieldSortScoring(boolean, boolean) to enable
> scoring.
>
>
> Sounds like you need to call that with at least the first arg set to true.

doh, yet another case of "even someone passing by will see the obvious
problem that you have been banging your head on for one hour".

Thank you for easily overcoming my stupidity :)

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: DisjunctionMaxQuery and custom Sort

Posted by Ian Lea <ia...@gmail.com>.
>From the javadocs for the search with sort method it appears you are calling:

NOTE: this does not compute scores by default; use
IndexSearcher.setDefaultFieldSortScoring(boolean, boolean) to enable
scoring.


Sounds like you need to call that with at least the first arg set to true.


--
Ian.


On Fri, Mar 5, 2010 at 9:13 AM, gabriele renzi <rf...@gmail.com> wrote:
> Hi everyone,
>
> In our search app we'd perform searches with a DisjunctionMaxQuery
> with code like
>
>  searcher.search(query, hits)
>
> Now we'd like to add a custom sub-sort so that when the search returns
> two documents with the same score they will be ordered by a custom
> field (this is not a boost for two reasons: first,  we already use
> boosting for other goals, second, we may like to add a third level of
> boosting in the future)
>
> I thought I could just change the former line to something like
>
>  searcher.search(query, null, hits, new Sort(SortField.SCORE_FIELD,
> new CustomSortField())
>
> but I had unexpected results, so I dropped our custom SortField, and
> tried the simple
>
>  searcher.search(query, null, hits, new Sort(SortField.SCORE_FIELD))
>
> which I though should have the same behaviour of our original code:
> yet, a large part of our tests failed because it appears that the
> results are not the same as above.
>
> So my question is threefold:
> 1. is the last query really not functionally equivalent to the first?
> 2. if not, how would the equivalent be?
> 3. and how can I perform a sub-sorting of the results by relevance
> first and my custom score field later?
>
> FWIW I am using lucene 2.9.1, java 1.6, OSX 10.6. Thanks in advance
> for any help.
>
> --
> blog en: http://www.riffraff.info
> blog it: http://riffraff.blogsome.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org