Q:

Lucene Java Sorting on TextField - Alphabetically

I am adding a field to a Document as such:
doc.add(new TextField("productName", prod.getProductName(), Field.Store.YES));

But when I do a search and try to sort, I do not get things in alphabetical order:
Sort sorter = new Sort(); 
SortField sortField = new SortField("productName", Type.STRING, false);
sorter.setSort(sortField);

Am I doing something wrong? How do I sort alphabetically?

A:

SortFields should not be tokenized.  If you need to have a field tokenized for searching effectively, and also sort on it, you create a separate, untokenized field (StringField) on the same content, and sort on that one, like:
doc.add(new TextField("productName", prod.getProductName(), Field.Store.YES));
doc.add(new StringField("productNameSort", prod.getProductName(), Field.Store.NO));

