: the custom Sort object seems a bit more direct.
: 
: I'm not very familiar with the solr source.  Can you give me some idea
: of how to get started -- maybe this is now a better discussion for
: solr-dev . . .

solr-user is fine ... writing plugins are a user level discussion topic 
(although maybe we should consider adding solr-plugin-dev list so people 
on solr-user who don't know (and don't want to know) anything about java 
don't have to read them)

Since the custom sorting you want to do is all based on a single field, 
the smallest granularity of a solr plugin you could write would be a new 
FieldType with a getSortField method that returns a new custom instance of 
SortField encapsulating the logic you want.  You can subclass the 
existing DateField class and just override that one method, to use your 
new code, you would just specify YourDateField in your schema.xml using 
it's full name (with java package).

that's all the special Solr work you need to do ... everything else is 
just extending some Classes the underlying Lucene Java API provides -- you 
can even test that most of your stuff is working using Lucene directly 
without ever worrying about Solr...

Your new SortField class can be very simple -- all you need to define is a 
new SortComparatorSource.  this is where the interesting stuff happens, 
SortComparatorSource instances are expected to decide, given an 
IndexReader and a fieldName how compare two documents.  Most of them use 
the Lucene FieldCache, which requires a single value per field -- you 
can make your SortComparatorSource do anything you want, as long as it 
produces something called a "ScoreDocComparator" which knows how to 
compare two documents and decide which one comes first.

All of these classes i mentioned (besides DateField) are Lucene classes 
that are documented in the Lucene javadocs...
   http://lucene.apache.org/java/2_3_1/api/index.html
...the best examples of how to use/extend them are probably the Unit 
tests. (just search for the class anmes)

Now: all that said, i'm honestly not sure what the best way to achieve 
your goal would be.  One appraoch would be to build an array of values 
like the FieldCache where you take into cosideration the current time while 
building it to decide which single value to give each doc.  the downside 
is that you can't cache that data stucture for very long, because time 
marches forward.  Another approach would be a more complicated data 
structure that still provides fast lookups per docid (array of arrays 
where the items in the subarrays are sorted so you can do a binary search)





-Hoss

Reply via email to