Hi folks,

Using Solr 4.6.0 in a cloud configuration, I'm developing a SearchComponent
that generates a custom score for each document.  Its operational flow
looks like this:

1. The score is derived from an analysis of search results coming out of
the QueryComponent.  Therefore, the component is installed after
QueryComponent in the processing chain.
2. The scores are generated in the component's process method (i.e. at the
shard level), and a map of uniqueKey:score is attached to each shard's
response at this point.
3. The shard-wise maps are combined in handleResponses and the aggregate
map is attached to the top-level distributed query's response.
4. In the finishStage method at the coordinator node level (i.e. response
stage = Get Fields), I'm presented with the final list of search results
sorted by Lucene score.  My custom scores are now added as fields to their
corresponding documents based on a uniqueKey lookup in the aggregate score
map.

Now I need to sort the final document list (or do it at the shard level) by
the custom score, but I'm having trouble understanding how to accomplish
this.  Yes, I could just sort my list (which will never exceed 1K results)
in finishStage and be done with it, but I'm trying to learn Solr best
practices to see if there's a better way.  At the end of the day, I'd like
to be able to take advantage of the "sort" request parameter to effect my
sort.

Given the current operational flow, it seems like I'd need to add a new
SortField for my score in step 4 and reinvoke QueryComponent's mergeIds
sort routine now that my custom field is present in the document list.  Of
course, I can't do that since it's all private code; nor does it seem wise
from an extensibility perspective to copy that code into my component for
use in this manner.

Reading Sujit Pal's blog post on "Custom Sorting in Solr using External
Database Data", I started down the path of defining a custom
FieldType/FieldComparatorSource for my score, but I didn't see how that
would help since the sort is still applied in QueryComponent - before my
custom score is available.  Regardless, Sujit's example seems pretty close
to what I want.

I must be misusing/misunderstanding the distributed design here in some
way.  Can an expert on distributed search components weigh in here?

Thanks!

Reply via email to