lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erick Erickson <>
Subject Re: Add a new field dynamically to each of the result docs and sort on it
Date Tue, 31 May 2016 20:34:40 GMT
To have Lucene/Solr do the sorting, your value must be in the
docs at search time. Consider the clause "&sort=my_field asc".
If rows=10, then only the top 10 docs are kept. So if a doc's score
is non-zero, it's value is compared against the 10 docs in the list and
either replaces one or is discarded.

You can't really do this dynamically. You don't know ahead of time
what docs will have non-zero score. Even if you did, you'd potentially
re-index your entire corpus (i.e. q=*:*&sort=something_dynamic) which
would be horrible.

Now, if what you want to do is just re-sort the topN docs, then you
can either create a custom component that re-sorts them or
use the ReRankingQParserPlugin.

But it sounds like this could really use some more thought. Have you
consider sorting by function? That can take the pre-indexed value in
the doc (or none) and sort the result by some set of calculations. You
haven't told us _what_ kinds of sorting you want to do so I have no
idea whether it applies or not.


On Tue, May 31, 2016 at 9:33 AM, Shawn Heisey <> wrote:
> On 5/31/2016 10:16 AM, Mark Robinson wrote:
>> sorry Eric... I did not phrase it right ... what I meant was the field is
>> there in the schema, but I do not have values for it when normal indexing
>> happens.
>> When a query comes in, I want to populate value for this field in the
>> results based on some values passed in the query.
>> So what needs to be accommodated in the result depends on a parameter in
>> the query and I would like to sort the final results on this field also,
>> which is dynamically populated.
>> What could be the best way to dynamically add value to this field based on
>> a query parameter and sort on this field also.
> Queries do not normally change the index.  They normally use a Lucene
> object that can search the index, not an object that can write to the index.
> I do not know whether a custom query component will be able to achieve
> write access to the index or not.  If it can, then you *might* be able
> to do what you want, but be aware that the index must meet the
> requirements for Atomic Update functionality, or the entire idea won't
> work at all:
> I have never written a custom query component, so I cannot say for sure
> that this is achievable.
>> Will a custom component help, with code in the *process *method to access
>> the results one by one and plug in this field help?
>> If so do I need to first index the value inside the *process *method for
>> reach result or is there a way to just add this value to each of my results
>> doc (no indexing) iterating through the result set and plugging in this
>> value for each result.
> The mention of a "process" method here suggests that you are thinking of
> an UpdateProcessor.  This would work if you are indexing ... but above
> you said this would happen at *query* time, which is a little bit different.
>> How will sort be applicable on this dynamically populated field as I am
>> already working on the results and is it too late to specify a sort and if
>> so how could it be possible.
> I do not know anything about custom code and sorting.
> Thanks,
> Shawn

View raw message