Example usage for org.apache.lucene.util.automaton Automata makeEmpty

List of usage examples for org.apache.lucene.util.automaton Automata makeEmpty

Introduction

In this page you can find the example usage for org.apache.lucene.util.automaton Automata makeEmpty.

Prototype

public static Automaton makeEmpty() 

Source Link

Document

Returns a new (deterministic) automaton with the empty language.

Usage

From source file:org.codelibs.elasticsearch.common.xcontent.support.XContentMapValues.java

License:Apache License

/**
 * Returns a function that filters a document map based on the given include and exclude rules.
 * @see #filter(Map, String[], String[]) for details
 *///from ww w.  j a  v  a  2  s.co  m
public static Function<Map<String, ?>, Map<String, Object>> filter(String[] includes, String[] excludes) {
    CharacterRunAutomaton matchAllAutomaton = new CharacterRunAutomaton(Automata.makeAnyString());

    CharacterRunAutomaton include;
    if (includes == null || includes.length == 0) {
        include = matchAllAutomaton;
    } else {
        Automaton includeA = Regex.simpleMatchToAutomaton(includes);
        includeA = makeMatchDotsInFieldNames(includeA);
        include = new CharacterRunAutomaton(includeA);
    }

    Automaton excludeA;
    if (excludes == null || excludes.length == 0) {
        excludeA = Automata.makeEmpty();
    } else {
        excludeA = Regex.simpleMatchToAutomaton(excludes);
        excludeA = makeMatchDotsInFieldNames(excludeA);
    }
    CharacterRunAutomaton exclude = new CharacterRunAutomaton(excludeA);

    // NOTE: We cannot use Operations.minus because of the special case that
    // we want all sub properties to match as soon as an object matches

    return (map) -> filter(map, include, 0, exclude, 0, matchAllAutomaton);
}

From source file:org.elasticsearch.index.reindex.TransportReindexAction.java

License:Apache License

/**
 * Build the {@link CharacterRunAutomaton} that represents the reindex-from-remote whitelist and make sure that it doesn't whitelist
 * the world.//ww w. j  a va  2  s .com
 */
static CharacterRunAutomaton buildRemoteWhitelist(List<String> whitelist) {
    if (whitelist.isEmpty()) {
        return new CharacterRunAutomaton(Automata.makeEmpty());
    }
    Automaton automaton = Regex.simpleMatchToAutomaton(whitelist.toArray(Strings.EMPTY_ARRAY));
    automaton = MinimizationOperations.minimize(automaton, Operations.DEFAULT_MAX_DETERMINIZED_STATES);
    if (Operations.isTotal(automaton)) {
        throw new IllegalArgumentException("Refusing to start because whitelist " + whitelist
                + " accepts all addresses. "
                + "This would allow users to reindex-from-remote any URL they like effectively having Elasticsearch make HTTP GETs "
                + "for them.");
    }
    return new CharacterRunAutomaton(automaton);
}

From source file:org.elasticsearch.xpack.security.authz.accesscontrol.FieldDataCacheWithFieldSubsetReaderTests.java

License:Open Source License

public void testSortedSetDVOrdinalsIndexFieldData_global() throws Exception {
    assertThat(indexFieldDataCache.topLevelBuilds, equalTo(0));
    IndexOrdinalsFieldData global = sortedSetDVOrdinalsIndexFieldData.loadGlobal(ir);
    AtomicOrdinalsFieldData atomic = global.load(ir.leaves().get(0));
    assertThat(atomic.getOrdinalsValues().getValueCount(), equalTo(numDocs));
    assertThat(indexFieldDataCache.topLevelBuilds, equalTo(1));

    DirectoryReader ir = FieldSubsetReader.wrap(this.ir, new CharacterRunAutomaton(Automata.makeEmpty()));
    global = sortedSetDVOrdinalsIndexFieldData.loadGlobal(ir);
    atomic = global.load(ir.leaves().get(0));
    assertThat(atomic.getOrdinalsValues().getValueCount(), equalTo(0L));
    assertThat(indexFieldDataCache.topLevelBuilds, equalTo(1));
}

From source file:org.elasticsearch.xpack.security.authz.accesscontrol.FieldDataCacheWithFieldSubsetReaderTests.java

License:Open Source License

public void testSortedSetDVOrdinalsIndexFieldData_segment() throws Exception {
    for (LeafReaderContext context : ir.leaves()) {
        AtomicOrdinalsFieldData atomic = sortedSetDVOrdinalsIndexFieldData.load(context);
        assertThat(atomic.getOrdinalsValues().getValueCount(), greaterThanOrEqualTo(1L));
    }/*from  w  w w .  j a  v a 2 s  .  c om*/

    DirectoryReader ir = FieldSubsetReader.wrap(this.ir, new CharacterRunAutomaton(Automata.makeEmpty()));
    for (LeafReaderContext context : ir.leaves()) {
        AtomicOrdinalsFieldData atomic = sortedSetDVOrdinalsIndexFieldData.load(context);
        assertThat(atomic.getOrdinalsValues().getValueCount(), equalTo(0L));
    }
    // dv based field data doesn't use index field data cache, so in the end noting should have been added
    assertThat(indexFieldDataCache.leafLevelBuilds, equalTo(0));
}

From source file:org.elasticsearch.xpack.security.authz.accesscontrol.FieldDataCacheWithFieldSubsetReaderTests.java

License:Open Source License

public void testPagedBytesIndexFieldData_global() throws Exception {
    assertThat(indexFieldDataCache.topLevelBuilds, equalTo(0));
    IndexOrdinalsFieldData global = pagedBytesIndexFieldData.loadGlobal(ir);
    AtomicOrdinalsFieldData atomic = global.load(ir.leaves().get(0));
    assertThat(atomic.getOrdinalsValues().getValueCount(), equalTo(numDocs));
    assertThat(indexFieldDataCache.topLevelBuilds, equalTo(1));

    DirectoryReader ir = FieldSubsetReader.wrap(this.ir, new CharacterRunAutomaton(Automata.makeEmpty()));
    global = pagedBytesIndexFieldData.loadGlobal(ir);
    atomic = global.load(ir.leaves().get(0));
    assertThat(atomic.getOrdinalsValues().getValueCount(), equalTo(0L));
    assertThat(indexFieldDataCache.topLevelBuilds, equalTo(1));
}

From source file:org.elasticsearch.xpack.security.authz.accesscontrol.FieldDataCacheWithFieldSubsetReaderTests.java

License:Open Source License

public void testPagedBytesIndexFieldData_segment() throws Exception {
    assertThat(indexFieldDataCache.leafLevelBuilds, equalTo(0));
    for (LeafReaderContext context : ir.leaves()) {
        AtomicOrdinalsFieldData atomic = pagedBytesIndexFieldData.load(context);
        assertThat(atomic.getOrdinalsValues().getValueCount(), greaterThanOrEqualTo(1L));
    }/*ww w . j  a v  a  2  s. c  o  m*/
    assertThat(indexFieldDataCache.leafLevelBuilds, equalTo(ir.leaves().size()));

    DirectoryReader ir = FieldSubsetReader.wrap(this.ir, new CharacterRunAutomaton(Automata.makeEmpty()));
    for (LeafReaderContext context : ir.leaves()) {
        AtomicOrdinalsFieldData atomic = pagedBytesIndexFieldData.load(context);
        assertThat(atomic.getOrdinalsValues().getValueCount(), equalTo(0L));
    }
    assertThat(indexFieldDataCache.leafLevelBuilds, equalTo(ir.leaves().size()));
}