I was sucessful with your hint and just need to solve another problem: The problem I have is that I have implemented a custome sorting by following your advice to code a QParserPlugin and to create a custom comparator as described in your book, and it really works But now I also would like to return those computed sort values by adding them to the SolrQueryResponse. I am calculating distances and would like to return the distance from the origin for each search result.
In your book you describe that it is possible by using this lucene search function: TopFieldDocs docs = searcher.search(query, null, 3, sort); and then to read the sort values: FieldDoc fieldDoc = (FieldDoc) docs.scoreDocs[0]; return -> fieldDoc.fields[0] But how can I do this inside Solr? I am using the default QueryComponent and of course I don’t want to make too many changes, because I don’t understand the inside of solr so much – it’s quite big and complicated and I didn’t find many documents explaining Solr. Is there maybe a workaround? Can I just store all my sort values and add them to the SolrQueryResponse at the end? Thanks, Markus Erik Hatcher wrote: > > Markus, > > A couple of code pointers for you: > > * QueryComponent - this is where results are generated, it uses a > SortSpec from the QParser. > > * QParser#getSort - creating a custom QParser you'll be able to > wire in your own custom sort > > You can write your own QParserPlugin and QParser, and configure it > into solrconfig.xml and should be good to go. Subclassing existing > classes, this should only be a handful of lines of code to do. > > Erik > > > On Dec 16, 2008, at 3:54 AM, psyron wrote: > >> >> I have the same problem, also need to plugin my "customComparator", >> but as >> there is no explanation of the framework, how a RequestHandler is >> working, >> what comes in, what comes out ... just impossible! >> >> Can someone explain where i have to add which code, to just have the >> same >> functionality as the StandardRequestHandler, but also adding a custom >> sorting? >> >> Thanks, >> Markus >> >> >> hossman wrote: >>> >>> >>> : Sort sort = new Sort(new SortField[] >>> : { SortField.FIELD_SCORE, new SortField(customValue, >>> SortField.FLOAT, >>> : true) }); >>> : indexSearcher.search(q, sort) >>> >>> that appears to just be a sort on score withe a secondary reversed >>> float sort on whatever field name is in the variable >>> "customValue" ... >>> assuming hte field name is "FIELD" that's hte same thing as... >>> sort=score+asc,+FIELD+desc >>> >>> : Sort sort = new Sort(new SortField(customValue, customComparator)) >>> : indexSearcher.search(q, sort) >>> >>> this is using a custom SortComparatorSource -- code you (or someone >>> else) >>> has written which is not part of Lucene and which tells lucene how to >>> order the documents using whatever crazy logic it wants ... for >>> obvious >>> reasons Solr can't do that same logic (since it doesn't know what >>> it is) >>> >>> although many things in Solr are easily customizable, just by >>> writting a >>> little factory and configuring it by class name, i'm afraind >>> SortComparatorSources aren't once of them. You could write a custom >>> RequestHandler which used your SortComparatorSource, or you could >>> write a >>> custom FieldType that used it anything someone sorted on that >>> field ... >>> but those are the best options i cna think of. >>> >>> >>> >>> -Hoss >>> >>> >>> >> >> -- >> View this message in context: >> http://www.nabble.com/Custom-Sorting-tp12222659p21029370.html >> Sent from the Solr - User mailing list archive at Nabble.com. > > > -- View this message in context: http://www.nabble.com/Custom-Sorting-tp12222659p22248512.html Sent from the Solr - User mailing list archive at Nabble.com.