Skip to content

Commit bf1b35a

Browse files
committed
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.
1 parent 71e24e2 commit bf1b35a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main/java/com/gitblit/tickets/TicketIndexer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import org.apache.lucene.document.Field.Store;
3232
import org.apache.lucene.document.IntField;
3333
import org.apache.lucene.document.LongField;
34+
import org.apache.lucene.document.NumericDocValuesField;
35+
import org.apache.lucene.document.SortedDocValuesField;
3436
import org.apache.lucene.document.TextField;
3537
import org.apache.lucene.index.DirectoryReader;
3638
import org.apache.lucene.index.IndexWriter;
@@ -49,6 +51,7 @@
4951
import org.apache.lucene.search.TopScoreDocCollector;
5052
import org.apache.lucene.store.Directory;
5153
import org.apache.lucene.store.FSDirectory;
54+
import org.apache.lucene.util.BytesRef;
5255
import org.slf4j.Logger;
5356
import org.slf4j.LoggerFactory;
5457

@@ -549,21 +552,25 @@ private void toDocField(Document doc, Lucene lucene, Date value) {
549552
return;
550553
}
551554
doc.add(new LongField(lucene.name(), value.getTime(), Store.YES));
555+
doc.add(new NumericDocValuesField(lucene.name(), value.getTime()));
552556
}
553557

554558
private void toDocField(Document doc, Lucene lucene, long value) {
555559
doc.add(new LongField(lucene.name(), value, Store.YES));
560+
doc.add(new NumericDocValuesField(lucene.name(), value));
556561
}
557562

558563
private void toDocField(Document doc, Lucene lucene, int value) {
559564
doc.add(new IntField(lucene.name(), value, Store.YES));
565+
doc.add(new NumericDocValuesField(lucene.name(), value));
560566
}
561567

562568
private void toDocField(Document doc, Lucene lucene, String value) {
563569
if (StringUtils.isEmpty(value)) {
564570
return;
565571
}
566572
doc.add(new org.apache.lucene.document.Field(lucene.name(), value, TextField.TYPE_STORED));
573+
doc.add(new SortedDocValuesField(lucene.name(), new BytesRef(value)));
567574
}
568575

569576
/**

0 commit comments

Comments
 (0)