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 Azhar Jassal <az...@gmail.com> on 2011/01/31 16:51:45 UTC

Sort results by number of document fields

Hi,

How can I use Lucene to sort search results by the number of fields each
document has? (highest to lowest - documents with more fields in my index
are better results)

Also my fields are named as URI's i.e. "<
http://www.w3.org/2000/01/rdf-schema#label>", how should I form queries with
field names containing such syntax? How shall I pass them in, escaped?

Thanks

Re: Sort results by number of document fields

Posted by Erik Hatcher <er...@gmail.com>.
On Jan 31, 2011, at 10:51 , Azhar Jassal wrote:
> How can I use Lucene to sort search results by the number of fields each
> document has? (highest to lowest - documents with more fields in my index
> are better results)

When you know you need to query on something you have available during indexing time, make your life easy and index it!  In other words, index the number of (other) fields as a numeric into a "num_fields" field or something like that.

This could be done automatically if you were to write a custom update processor and add it to the update processing chain, but easy enough to do in most custom indexers I've ever come across as well.

> Also my fields are named as URI's i.e. "<
> http://www.w3.org/2000/01/rdf-schema#label>", how should I form queries with
> field names containing such syntax? How shall I pass them in, escaped?

Good luck on this one... you'll have to contend with escaping (with a backslash) if you're using the "lucene" query parser, and perhaps other related headaches with other query parsers depending on how they do their thing underneath.

	Erik


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