Add DocValues to support sorting of ticket index fields. In order to support sorting, Lucene 5 needs DocValue fields in an index. So in order to make the ticket index work, i.e. show any tickets on the tickets page, the ticket index needs to be changed, adding a DocValues field. The DocValuesFields are implemented for the current index, which does not use multiple values for a field. Should at any time in the future an existing numeric field get multiple values stored in a document, then the index needs to know that and use SortedNumeric DocValues and SortFields instead.
diff --git a/src/main/java/com/gitblit/tickets/TicketIndexer.java b/src/main/java/com/gitblit/tickets/TicketIndexer.java index b765cc6..8aab74b 100644 --- a/src/main/java/com/gitblit/tickets/TicketIndexer.java +++ b/src/main/java/com/gitblit/tickets/TicketIndexer.java
@@ -31,6 +31,8 @@ import org.apache.lucene.document.Field.Store; import org.apache.lucene.document.IntField; import org.apache.lucene.document.LongField; +import org.apache.lucene.document.NumericDocValuesField; +import org.apache.lucene.document.SortedDocValuesField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexWriter; @@ -49,6 +51,7 @@ import org.apache.lucene.search.TopScoreDocCollector; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; +import org.apache.lucene.util.BytesRef; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -549,14 +552,17 @@ return; } doc.add(new LongField(lucene.name(), value.getTime(), Store.YES)); + doc.add(new NumericDocValuesField(lucene.name(), value.getTime())); } private void toDocField(Document doc, Lucene lucene, long value) { doc.add(new LongField(lucene.name(), value, Store.YES)); + doc.add(new NumericDocValuesField(lucene.name(), value)); } private void toDocField(Document doc, Lucene lucene, int value) { doc.add(new IntField(lucene.name(), value, Store.YES)); + doc.add(new NumericDocValuesField(lucene.name(), value)); } private void toDocField(Document doc, Lucene lucene, String value) { @@ -564,6 +570,7 @@ return; } doc.add(new org.apache.lucene.document.Field(lucene.name(), value, TextField.TYPE_STORED)); + doc.add(new SortedDocValuesField(lucene.name(), new BytesRef(value))); } /**