use of org.apache.lucene.document.StringField in project jackrabbit-oak by apache.
the class LuceneDocumentMaker method addNodeNameField.
/**
* Extracts the local name of the current node ignoring any namespace prefix
*
* @param name node name
*/
private static void addNodeNameField(List<Field> fields, String name) {
//TODO Need to check if it covers all cases
int colon = name.indexOf(':');
String value = colon < 0 ? name : name.substring(colon + 1);
//For now just add a single term. Later we can look into using different analyzer
//to analyze the node name and add multiple terms. Like add multiple terms for a
//cameCase file name to allow faster like search
fields.add(new StringField(FieldNames.NODE_NAME, value, Field.Store.NO));
}
use of org.apache.lucene.document.StringField in project jackrabbit-oak by apache.
the class LuceneDocumentMaker method addTypedFields.
private boolean addTypedFields(List<Field> fields, PropertyState property, String pname) {
int tag = property.getType().tag();
boolean fieldAdded = false;
for (int i = 0; i < property.count(); i++) {
Field f;
if (tag == Type.LONG.tag()) {
f = new LongField(pname, property.getValue(Type.LONG, i), Field.Store.NO);
} else if (tag == Type.DATE.tag()) {
String date = property.getValue(Type.DATE, i);
f = new LongField(pname, FieldFactory.dateToLong(date), Field.Store.NO);
} else if (tag == Type.DOUBLE.tag()) {
f = new DoubleField(pname, property.getValue(Type.DOUBLE, i), Field.Store.NO);
} else if (tag == Type.BOOLEAN.tag()) {
f = new StringField(pname, property.getValue(Type.BOOLEAN, i).toString(), Field.Store.NO);
} else {
f = new StringField(pname, property.getValue(Type.STRING, i), Field.Store.NO);
}
fields.add(f);
fieldAdded = true;
}
return fieldAdded;
}
use of org.apache.lucene.document.StringField in project jackrabbit-oak by apache.
the class LuceneDocumentMaker method indexNullCheckEnabledProps.
private boolean indexNullCheckEnabledProps(String path, List<Field> fields, NodeState state) {
boolean fieldAdded = false;
for (PropertyDefinition pd : indexingRule.getNullCheckEnabledProperties()) {
if (isPropertyNull(state, pd)) {
fields.add(new StringField(FieldNames.NULL_PROPS, pd.name, Field.Store.NO));
fieldAdded = true;
}
}
return fieldAdded;
}
use of org.apache.lucene.document.StringField in project jackrabbit-oak by apache.
the class DefaultIndexReaderFactoryTest method multipleReaders_SingleSuggester.
@Test
public void multipleReaders_SingleSuggester() throws Exception {
LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, null);
enabledSuggestorForSomeProp();
defn = new IndexDefinition(root, builder.getNodeState(), "/foo");
LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
//Suggester field is only present for document in default mount
Document doc = newDoc("/content/en");
doc.add(new StringField(FieldNames.SUGGEST, "test", null));
writer.updateDocument("/content/en", doc);
writer.updateDocument("/libs/config", newDoc("/libs/config"));
writer.close(0);
LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
//Suggester should be present for all though it may be empty
for (LuceneIndexReader reader : readers) {
assertNotNull(reader.getReader());
assertNotNull(reader.getSuggestDirectory());
assertNotNull(reader.getLookup());
}
}
use of org.apache.lucene.document.StringField in project jackrabbit-oak by apache.
the class DefaultIndexReaderFactoryTest method suggesterDir.
@Test
public void suggesterDir() throws Exception {
LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, null);
enabledSuggestorForSomeProp();
defn = new IndexDefinition(root, builder.getNodeState(), "/foo");
LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
Document doc = newDoc("/content/en");
doc.add(new StringField(FieldNames.SUGGEST, "test", null));
writer.updateDocument("/content/en", doc);
writer.close(0);
LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
LuceneIndexReader reader = readers.get(0);
assertNotNull(reader.getReader());
assertNotNull(reader.getSuggestDirectory());
assertNotNull(reader.getLookup());
}
Aggregations