summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/tickets/TicketIndexer.java
diff options
context:
space:
mode:
authorFlorian Zschocke <florian.zschocke@devolo.de>2017-02-26 18:44:02 +0100
committerFlorian Zschocke <florian.zschocke@devolo.de>2017-03-05 20:27:22 +0100
commitbf1b35aac29b6c0d5e918f00d99a0632e4925b51 (patch)
tree09815483391193f44dec0f9d53e87217c8ee0e21 /src/main/java/com/gitblit/tickets/TicketIndexer.java
parent71e24e22cca3f85996b8a0d1951311b4592f2213 (diff)
downloadgitblit-bf1b35aac29b6c0d5e918f00d99a0632e4925b51.tar.gz
gitblit-bf1b35aac29b6c0d5e918f00d99a0632e4925b51.zip
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.
Diffstat (limited to 'src/main/java/com/gitblit/tickets/TicketIndexer.java')
-rw-r--r--src/main/java/com/gitblit/tickets/TicketIndexer.java7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/main/java/com/gitblit/tickets/TicketIndexer.java b/src/main/java/com/gitblit/tickets/TicketIndexer.java
index b765cc66..8aab74ba 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.Document;
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.TopFieldDocs;
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 @@ public class TicketIndexer {
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 @@ public class TicketIndexer {
return;
}
doc.add(new org.apache.lucene.document.Field(lucene.name(), value, TextField.TYPE_STORED));
+ doc.add(new SortedDocValuesField(lucene.name(), new BytesRef(value)));
}
/**