Search in sources :

Example 1 with BoolFilterBuilder

use of org.elasticsearch.index.query.BoolFilterBuilder in project stash-codesearch-plugin by palantir.

the class SearchFilterUtils method authorFilter.

public FilterBuilder authorFilter(Iterable<String> authors) {
    boolean filterAdded = false;
    BoolFilterBuilder filter = boolFilter();
    for (String author : authors) {
        String[] toks = author.split("\\W+");
        boolean emptyTokens = true;
        for (String tok : toks) {
            if (!tok.isEmpty()) {
                emptyTokens = false;
                break;
            }
        }
        if (emptyTokens) {
            continue;
        }
        // Name filters
        BoolFilterBuilder nameFilter = boolFilter();
        for (String tok : toks) {
            if (!tok.isEmpty()) {
                nameFilter.must(termFilter("commit.authorname", tok.toLowerCase()));
            }
        }
        filter.should(nameFilter);
        // Email filters
        BoolFilterBuilder emailFilter = boolFilter();
        for (String tok : toks) {
            if (!tok.isEmpty()) {
                emailFilter.must(termFilter("commit.authoremail", tok.toLowerCase()));
            }
        }
        filter.should(emailFilter);
        filterAdded = true;
    }
    return filterAdded ? filter.should(typeFilter("file")) : matchAllFilter();
}
Also used : BoolFilterBuilder(org.elasticsearch.index.query.BoolFilterBuilder)

Example 2 with BoolFilterBuilder

use of org.elasticsearch.index.query.BoolFilterBuilder in project stash-codesearch-plugin by palantir.

the class SearchFilterUtils method repositoryFilter.

public FilterBuilder repositoryFilter(Iterable<String> repositories) {
    boolean filterAdded = false;
    BoolFilterBuilder filter = boolFilter();
    for (String repository : repositories) {
        repository = repository.trim();
        if (repository.isEmpty()) {
            continue;
        }
        filter.should(termFilter("repository", repository).cache(true).cacheKey("CACHE^REPOFILTER^" + repository));
        filterAdded = true;
    }
    return filterAdded ? filter : matchAllFilter();
}
Also used : BoolFilterBuilder(org.elasticsearch.index.query.BoolFilterBuilder)

Example 3 with BoolFilterBuilder

use of org.elasticsearch.index.query.BoolFilterBuilder in project stash-codesearch-plugin by palantir.

the class SearchFilterUtils method refFilter.

public FilterBuilder refFilter(Iterable<String> refs) {
    boolean filterAdded = false;
    BoolFilterBuilder filter = boolFilter();
    for (String ref : refs) {
        String[] toks = ref.split("[/\\s]+");
        // Make sure there's at least one non-empty token
        boolean emptyTokens = true;
        for (String tok : toks) {
            if (!tok.isEmpty()) {
                emptyTokens = false;
                break;
            }
        }
        if (emptyTokens) {
            continue;
        }
        BoolFilterBuilder refFilter = boolFilter().cache(true).cacheKey("CACHE^REFANDFILTER^" + ref);
        for (String tok : toks) {
            if (!tok.isEmpty()) {
                refFilter.must(termFilter("refs", tok.toLowerCase()));
            }
        }
        filter.should(refFilter);
        filterAdded = true;
    }
    return filterAdded ? filter : matchAllFilter();
}
Also used : BoolFilterBuilder(org.elasticsearch.index.query.BoolFilterBuilder)

Example 4 with BoolFilterBuilder

use of org.elasticsearch.index.query.BoolFilterBuilder in project stash-codesearch-plugin by palantir.

the class SearchFilterUtils method extensionFilter.

public FilterBuilder extensionFilter(Iterable<String> extensions) {
    boolean filterAdded = false;
    BoolFilterBuilder filter = boolFilter();
    for (String extension : extensions) {
        extension = extension.trim();
        if (extension.isEmpty()) {
            continue;
        }
        filter.should(termFilter("extension", extension).cache(true).cacheKey("CACHE^EXTENSIONFILTER^" + extension));
        filterAdded = true;
    }
    return filterAdded ? filter.should(typeFilter("commit")) : matchAllFilter();
}
Also used : BoolFilterBuilder(org.elasticsearch.index.query.BoolFilterBuilder)

Example 5 with BoolFilterBuilder

use of org.elasticsearch.index.query.BoolFilterBuilder in project stash-codesearch-plugin by palantir.

the class SearchFilterUtils method projectFilter.

public FilterBuilder projectFilter(Iterable<String> projects) {
    boolean filterAdded = false;
    BoolFilterBuilder filter = boolFilter();
    for (String project : projects) {
        project = project.trim();
        if (project.isEmpty()) {
            continue;
        }
        filter.should(termFilter("project", project).cache(true).cacheKey("CACHE^PROJECTFILTER^" + project));
        filterAdded = true;
    }
    return filterAdded ? filter : matchAllFilter();
}
Also used : BoolFilterBuilder(org.elasticsearch.index.query.BoolFilterBuilder)

Aggregations

BoolFilterBuilder (org.elasticsearch.index.query.BoolFilterBuilder)6 Repository (com.atlassian.stash.repository.Repository)1 MessageDigest (java.security.MessageDigest)1