November 7, 2007

Make a Lucene field sortable and searchable

The java code snippet below will add searchable (TOKENIZED) fields and
sortable (UN_TOKENIZED) fields to a Lucene document.

if (value != null)
doc.add(new Field(key, value, Field.Store.YES, Field.Index.TOKENIZED));
if (key.equalsIgnoreCase("author") || key.equalsIgnoreCase("title") || key.equalsIgnoreCase("date") )
doc.add(new Field(key + "_sortable", value, Field.Store.YES, Field.Index.UN_TOKENIZED));


This is from the ag econ project file:


October 22, 2007

Attributes of the fields in the Lucence database (in dspace) + sortable problem

I used the code below:

JavaCodeToDumpLuceneAttributes.html and found out that the fields in the lucene DB had the following attributes:

dspaceFields.html Fields cannot be tokenized if they are to be sortable. So none of the fields other then the handle are sortable.