use of org.apache.jackrabbit.oak.plugins.memory.StringPropertyState in project jackrabbit-oak by apache.
the class LuceneDocumentMaker method makeDocument.
@CheckForNull
public Document makeDocument(NodeState state, boolean isUpdate, List<PropertyState> propertiesModified) throws IOException {
boolean facet = false;
List<Field> fields = new ArrayList<Field>();
boolean dirty = false;
//We 'intentionally' are indexing node names only on root state as we don't support indexing relative or
//regex for node name indexing
PropertyState nodenamePS = new StringPropertyState(FieldNames.NODE_NAME, getName(path));
for (PropertyState property : Iterables.concat(state.getProperties(), Collections.singleton(nodenamePS))) {
String pname = property.getName();
if (!isVisible(pname) && !FieldNames.NODE_NAME.equals(pname)) {
continue;
}
PropertyDefinition pd = indexingRule.getConfig(pname);
if (pd == null || !pd.index) {
continue;
}
if (pd.ordered) {
dirty |= addTypedOrderedFields(fields, property, pname, pd);
}
dirty |= indexProperty(path, fields, state, property, pname, pd);
facet |= pd.facet;
}
boolean[] dirties = indexAggregates(path, fields, state);
// any (aggregate) indexing happened
dirty |= dirties[0];
// facet indexing during (index-time) aggregation
facet |= dirties[1];
dirty |= indexNullCheckEnabledProps(path, fields, state);
dirty |= indexFunctionRestrictions(path, fields, state);
dirty |= indexNotNullCheckEnabledProps(path, fields, state);
dirty |= augmentCustomFields(path, fields, state);
// Check if a node having a single property was modified/deleted
if (!dirty) {
dirty = indexIfSinglePropertyRemoved(propertiesModified);
}
if (isUpdate && !dirty) {
// updated the state but had no relevant changes
return null;
}
String name = getName(path);
if (indexingRule.isNodeNameIndexed()) {
addNodeNameField(fields, name);
dirty = true;
}
//none of the properties are indexed
if (!indexingRule.indexesAllNodesOfMatchingType() && !dirty) {
return null;
}
Document document = new Document();
document.add(newPathField(path));
if (indexingRule.isFulltextEnabled()) {
document.add(newFulltextField(name));
}
if (definition.evaluatePathRestrictions()) {
document.add(newAncestorsField(PathUtils.getParentPath(path)));
document.add(newDepthField(path));
}
// because of LUCENE-5833 we have to merge the suggest fields into a single one
Field suggestField = null;
for (Field f : fields) {
if (FieldNames.SUGGEST.equals(f.name())) {
if (suggestField == null) {
suggestField = FieldFactory.newSuggestField(f.stringValue());
} else {
suggestField = FieldFactory.newSuggestField(suggestField.stringValue(), f.stringValue());
}
} else {
document.add(f);
}
}
if (suggestField != null) {
document.add(suggestField);
}
if (facet && isFacetingEnabled()) {
document = getFacetsConfig().build(document);
}
return document;
}
Aggregations