<commit_before>package org.lilyproject.indexer.model.indexerconf;

import java.util.List;

import org.lilyproject.repository.api.QName;
import org.lilyproject.repository.api.Record;
import org.lilyproject.repository.api.RepositoryException;
import org.lilyproject.repository.api.SchemaId;
import org.lilyproject.repository.api.Scope;
import org.lilyproject.util.repo.VTaggedRecord;

public class MatchNode extends ContainerMappingNode {

    private final RecordMatcher recordMatcher;

    public MatchNode(RecordMatcher recordMatcher) {
        this.recordMatcher = recordMatcher;
    }

    public RecordMatcher getRecordMatcher() {
        return recordMatcher;
    }

    /**
     *
     *
     * If the conditions match, we need to evaluate all children
     *
     */
    @Override
    public boolean isIndexAffectedByUpdate(VTaggedRecord vtRecord, Scope scope) throws InterruptedException,
            RepositoryException {
        // If something changed which may affect the outcome of the match
        // condition,
        // we must reindex (immediately return true)

        if (recordMatcher.dependsOnRecordType()) {
            if (vtRecord.getRecordEvent().getRecordTypeChanged()) {
                return true;
            }
        }

        for (QName fieldTypeName: recordMatcher.getFieldDependencies()) {
            // FIXME: updatedFieldsByScope contains FieldType, not QName
            if (vtRecord.getUpdatedFieldsByScope().get(scope).contains(fieldTypeName)) {
                return true;
            }
        }

        if (recordMatcher.matches(vtRecord.getRecord())) {
            return childrenAffectedByUpdate(vtRecord, scope);
        } else {
            return false;
        }
    }

    public void collectIndexFields(List<IndexField> indexFields, Record record, long version, SchemaId vtag) {
        if (recordMatcher.matches(record)) {
            super.collectIndexFields(indexFields, record, version, vtag);
        }
    }

}<commit_msg>LILY-360 Fix the 'field' check of <match> elements (note: doesn't work until merged with other work)<commit_after>package org.lilyproject.indexer.model.indexerconf;

import java.util.List;

import org.lilyproject.repository.api.FieldType;
import org.lilyproject.repository.api.Record;
import org.lilyproject.repository.api.RepositoryException;
import org.lilyproject.repository.api.SchemaId;
import org.lilyproject.repository.api.Scope;
import org.lilyproject.util.repo.VTaggedRecord;

public class MatchNode extends ContainerMappingNode {

    private final RecordMatcher recordMatcher;

    public MatchNode(RecordMatcher recordMatcher) {
        this.recordMatcher = recordMatcher;
    }

    public RecordMatcher getRecordMatcher() {
        return recordMatcher;
    }

    /**
     *
     *
     * If the conditions match, we need to evaluate all children
     *
     */
    @Override
    public boolean isIndexAffectedByUpdate(VTaggedRecord vtRecord, Scope scope) throws InterruptedException,
            RepositoryException {
        // If the matcher uses the record type and the record type changed, we must reindex.
        if (recordMatcher.dependsOnRecordType()) {
            if (vtRecord.getRecordEvent().getRecordTypeChanged()) {
                return true;
            }
        }

        // If the matcher uses fields and any of the fields were changed, we must reindex.
        for (FieldType ft: vtRecord.getUpdatedFieldsByScope().get(scope)) {
            if (recordMatcher.getFieldDependencies().contains(ft.getName())) {
                return true;
            }
        }

        if (recordMatcher.matches(vtRecord.getRecord())) {
            return childrenAffectedByUpdate(vtRecord, scope);
        } else {
            return false;
        }
    }

    public void collectIndexFields(List<IndexField> indexFields, Record record, long version, SchemaId vtag) {
        if (recordMatcher.matches(record)) {
            super.collectIndexFields(indexFields, record, version, vtag);
        }
    }

}
{'fraction_non_alphanumeric': 0.08445440956651719, 'fraction_numerical': 0.0007473841554559044, 'mean_word_length': 2.7488328664799253, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5400216', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1040, 'n_words': 255}