Lucene: Search commit messages using secondary index

Change-Id: Iff2285d0b4934e9871e7635ae3681555f06ea336
This commit is contained in:
Gohulan Balachandran
2013-06-25 14:33:51 -06:00
committed by Edwin Kempin
parent a7c0ba2b50
commit 122ecd55fc
6 changed files with 72 additions and 34 deletions

View File

@@ -57,6 +57,7 @@ import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.IntField;
import org.apache.lucene.document.LongField;
import org.apache.lucene.document.StringField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
@@ -66,6 +67,7 @@ import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.RegexpQuery;
import org.apache.lucene.search.ScoreDoc;
@@ -279,6 +281,8 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener {
return exactQuery(p);
} else if (p.getType() == FieldType.PREFIX) {
return prefixQuery(p);
} else if (p.getType() == FieldType.FULL_TEXT) {
return fullTextQuery(p);
} else if (p instanceof SortKeyPredicate) {
return sortKeyQuery((SortKeyPredicate) p);
} else {
@@ -363,6 +367,10 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener {
return new PrefixQuery(new Term(p.getField().getName(), p.getValue()));
}
private Query fullTextQuery(IndexPredicate<ChangeData> p) {
return new FuzzyQuery(new Term(p.getField().getName(), p.getValue()));
}
private static class QuerySource implements ChangeDataSource {
// TODO(dborowitz): Push limit down from predicate tree.
private static final int LIMIT = 1000;
@@ -484,6 +492,10 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener {
for (Object value : values) {
doc.add(new StringField(name, (String) value, store));
}
} else if (f.getType() == FieldType.FULL_TEXT) {
for (Object value : values) {
doc.add(new TextField(name, (String) value, store));
}
} else {
throw badFieldType(f.getType());
}