Search in sources :

Example 1 with StringPropertyState

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;
}
Also used : FieldFactory.newFulltextField(org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newFulltextField) LongField(org.apache.lucene.document.LongField) StringField(org.apache.lucene.document.StringField) SortedSetDocValuesFacetField(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetField) FieldFactory.newDepthField(org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newDepthField) FieldFactory.newPropertyField(org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newPropertyField) DoubleDocValuesField(org.apache.lucene.document.DoubleDocValuesField) FieldFactory.newPathField(org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newPathField) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) DoubleField(org.apache.lucene.document.DoubleField) SortedDocValuesField(org.apache.lucene.document.SortedDocValuesField) FieldFactory.newAncestorsField(org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newAncestorsField) Field(org.apache.lucene.document.Field) StringPropertyState(org.apache.jackrabbit.oak.plugins.memory.StringPropertyState) ArrayList(java.util.ArrayList) Document(org.apache.lucene.document.Document) StringPropertyState(org.apache.jackrabbit.oak.plugins.memory.StringPropertyState) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) CheckForNull(javax.annotation.CheckForNull)

Aggregations

ArrayList (java.util.ArrayList)1 CheckForNull (javax.annotation.CheckForNull)1 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)1 FieldFactory.newAncestorsField (org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newAncestorsField)1 FieldFactory.newDepthField (org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newDepthField)1 FieldFactory.newFulltextField (org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newFulltextField)1 FieldFactory.newPathField (org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newPathField)1 FieldFactory.newPropertyField (org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newPropertyField)1 StringPropertyState (org.apache.jackrabbit.oak.plugins.memory.StringPropertyState)1 Document (org.apache.lucene.document.Document)1 DoubleDocValuesField (org.apache.lucene.document.DoubleDocValuesField)1 DoubleField (org.apache.lucene.document.DoubleField)1 Field (org.apache.lucene.document.Field)1 LongField (org.apache.lucene.document.LongField)1 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)1 SortedDocValuesField (org.apache.lucene.document.SortedDocValuesField)1 StringField (org.apache.lucene.document.StringField)1 SortedSetDocValuesFacetField (org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetField)1