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?
SortField
s 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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With