Package org.apache.lucene.search

Examples of org.apache.lucene.search.Filter


        if (filters.isEmpty()) {
            throw new QueryParsingException(parseContext.index(), "[or] filter requires 'filters' to be set on it'");
        }

        // no need to cache this one
        Filter filter = new AndFilter(filters);
        if (cache) {
            filter = parseContext.cacheFilter(filter, cacheKey);
        }
        if (filterName != null) {
            parseContext.addNamedFilter(filterName, filter);
View Full Code Here


        if (value == null) {
            throw new QueryParsingException(parseContext.index(), "No value specified for term filter");
        }

        Filter filter = null;
        MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
        if (smartNameFieldMappers != null) {
            if (smartNameFieldMappers.hasMapper()) {
                filter = smartNameFieldMappers.mapper().fieldFilter(value);
            }
View Full Code Here

        if (fieldName == null) {
            throw new QueryParsingException(parseContext.index(), "exists must be provided with a [field]");
        }

        Filter filter = null;
        MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
        if (smartNameFieldMappers != null) {
            if (smartNameFieldMappers.hasMapper()) {
                filter = smartNameFieldMappers.mapper().rangeFilter(null, null, true, true);
            }
View Full Code Here

        indexWriter.deleteDocuments(new Term("id", "1"));
        reader = refreshReader(reader);
        searcher = new IndexSearcher(reader);
        TermFilter filter = new TermFilter(new Term("id", "1"));
        Filter cachedFilter = filterCache.cache(filter);
        long constantScoreCount = filter == cachedFilter ? 0 : 1;
        // sadly, when caching based on cacheKey with NRT, this fails, that's why we have DeletionAware one
        assertThat(Lucene.count(searcher, new ConstantScoreQuery(cachedFilter), -1), equalTo(constantScoreCount));
        assertThat(Lucene.count(searcher, new DeletionAwareConstantScoreQuery(cachedFilter), -1), equalTo(0l));
        assertThat(Lucene.count(searcher, new FilteredQuery(new MatchAllDocsQuery(), cachedFilter), -1), equalTo(0l));
View Full Code Here

    @Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
        XContentParser parser = parseContext.parser();

        Query query = null;
        Filter filter = null;
        float boost = 1.0f;
        boolean cache = false;
        CacheKeyFilter.Key cacheKey = null;

        String currentFieldName = null;
View Full Code Here

    @Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
        XContentParser parser = parseContext.parser();

        Query query = null;
        Filter filter = null;
        float boost = 1.0f;
        String scope = null;
        String path = null;
        BlockJoinQuery.ScoreMode scoreMode = BlockJoinQuery.ScoreMode.Avg;

        // we need a late binding filter so we can inject a parent nested filter inner nested queries
        LateBindingParentFilter currentParentFilterContext = parentFilterContext.get();

        LateBindingParentFilter usAsParentFilter = new LateBindingParentFilter();
        parentFilterContext.set(usAsParentFilter);

        String currentFieldName = null;
        XContentParser.Token token;
        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token == XContentParser.Token.FIELD_NAME) {
                currentFieldName = parser.currentName();
            } else if (token == XContentParser.Token.START_OBJECT) {
                if ("query".equals(currentFieldName)) {
                    query = parseContext.parseInnerQuery();
                } else if ("filter".equals(currentFieldName)) {
                    filter = parseContext.parseInnerFilter();
                }
            } else if (token.isValue()) {
                if ("path".equals(currentFieldName)) {
                    path = parser.text();
                } else if ("boost".equals(currentFieldName)) {
                    boost = parser.floatValue();
                } else if ("_scope".equals(currentFieldName)) {
                    scope = parser.text();
                } else if ("score_mode".equals(currentFieldName) || "scoreMode".equals(scoreMode)) {
                    String sScoreMode = parser.text();
                    if ("avg".equals(sScoreMode)) {
                        scoreMode = BlockJoinQuery.ScoreMode.Avg;
                    } else if ("max".equals(sScoreMode)) {
                        scoreMode = BlockJoinQuery.ScoreMode.Max;
                    } else if ("total".equals(sScoreMode)) {
                        scoreMode = BlockJoinQuery.ScoreMode.Total;
                    } else if ("none".equals(sScoreMode)) {
                        scoreMode = BlockJoinQuery.ScoreMode.None;
                    } else {
                        throw new QueryParsingException(parseContext.index(), "illegal score_mode for nested query [" + sScoreMode + "]");
                    }
                }
            }
        }
        if (query == null && filter == null) {
            throw new QueryParsingException(parseContext.index(), "[nested] requires either 'query' or 'filter' field");
        }
        if (path == null) {
            throw new QueryParsingException(parseContext.index(), "[nested] requires 'path' field");
        }

        if (filter != null) {
            query = new DeletionAwareConstantScoreQuery(filter);
        }

        query.setBoost(boost);

        MapperService.SmartNameObjectMapper mapper = parseContext.mapperService().smartNameObjectMapper(path);
        if (mapper == null) {
            throw new QueryParsingException(parseContext.index(), "[nested] failed to find nested object under path [" + path + "]");
        }
        ObjectMapper objectMapper = mapper.mapper();
        if (objectMapper == null) {
            throw new QueryParsingException(parseContext.index(), "[nested] failed to find nested object under path [" + path + "]");
        }
        if (!objectMapper.nested().isNested()) {
            throw new QueryParsingException(parseContext.index(), "[nested] nested object under path [" + path + "] is not of nested type");
        }

        Filter childFilter = parseContext.cacheFilter(objectMapper.nestedTypeFilter(), null);
        usAsParentFilter.filter = childFilter;
        // wrap the child query to only work on the nested path type
        query = new FilteredQuery(query, childFilter);

        Filter parentFilter = currentParentFilterContext;
        if (parentFilter == null) {
            parentFilter = NonNestedDocsFilter.INSTANCE;
            if (mapper.hasDocMapper()) {
                // filter based on the type...
                parentFilter = mapper.docMapper().typeFilter();
View Full Code Here

                    cacheKey = new CacheKeyFilter.Key(parser.text());
                }
            }
        }

        Filter filter = termsFilter;
        if (cache) {
            filter = parseContext.cacheFilter(filter, cacheKey);
        }

        filter = wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext);
View Full Code Here

        FieldMapper mapper = smartNameFieldMappers.mapper();
        if (!(mapper instanceof NumberFieldMapper)) {
            throw new QueryParsingException(parseContext.index(), "Field [" + fieldName + "] is not a numeric type");
        }
        Filter filter = ((NumberFieldMapper) mapper).rangeFilter(parseContext.indexCache().fieldData(), from, to, includeLower, includeUpper);

        if (cache) {
            filter = parseContext.cacheFilter(filter, cacheKey);
        }
        filter = wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext);
View Full Code Here

        }
        if (params == null) {
            params = Maps.newHashMap();
        }

        Filter filter = new ScriptFilter(scriptLang, script, params, parseContext.scriptService());
        if (cache) {
            filter = parseContext.cacheFilter(filter, cacheKey);
        }
        if (filterName != null) {
            parseContext.addNamedFilter(filterName, filter);
View Full Code Here

        if (fieldName == null) {
            throw new QueryParsingException(parseContext.index(), "No field specified for range filter");
        }

        Filter filter = null;
        MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
        if (smartNameFieldMappers != null) {
            if (smartNameFieldMappers.hasMapper()) {
                filter = smartNameFieldMappers.mapper().rangeFilter(from, to, includeLower, includeUpper);
            }
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.Filter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.