public Query nullValueQuery() { if (nullValue == null) { return null; } return new ConstantScoreQuery(termQuery(nullValue, null)); }
/** * Visible only for testing purposes. */ List<Query> createTermQueries(QueryShardContext context) { final MappedFieldType fieldType = context.fieldMapper(fieldName); final List<Query> queries = new ArrayList<>(values.size()); for (Object value : values) { if (fieldType != null) { queries.add(fieldType.termQuery(value, context)); } else { queries.add(new TermQuery(new Term(fieldName, BytesRefs.toBytesRef(value)))); } } return queries; }
@Override protected Query doToQuery(QueryShardContext context) throws IOException { Query query = null; MappedFieldType mapper = context.fieldMapper(this.fieldName); if (mapper != null) { query = mapper.termQuery(this.value, context); } if (query == null) { query = new TermQuery(new Term(this.fieldName, BytesRefs.toBytesRef(this.value))); } return query; }
protected final Query termQuery(MappedFieldType fieldType, BytesRef value, boolean lenient) { try { return fieldType.termQuery(value, context); } catch (RuntimeException e) { if (lenient) { return newLenientFieldQuery(fieldType.name(), e); } throw e; } }
public Query typeFilter(QueryShardContext context) { return typeMapper().fieldType().termQuery(type, context); }
@Override protected SpanQuery doToQuery(QueryShardContext context) throws IOException { MappedFieldType mapper = context.fieldMapper(fieldName); Term term; if (mapper == null) { term = new Term(fieldName, BytesRefs.toBytesRef(value)); } else { Query termQuery = mapper.termQuery(value, context); term = MappedFieldType.extractTerm(termQuery); } return new SpanTermQuery(term); }
@Override protected Query newTermQuery(Term term) { MappedFieldType ft = context.fieldMapper(term.field()); if (ft == null) { return newUnmappedFieldQuery(term.field()); } return ft.termQuery(term.bytes(), context); }
fieldType.termQuery("", context); } catch (QueryShardException |UnsupportedOperationException e) {
/** Build a constant-scoring query that matches all values. The default implementation uses a * {@link ConstantScoreQuery} around a {@link BooleanQuery} whose {@link Occur#SHOULD} clauses * are generated with {@link #termQuery}. */ public Query termsQuery(List<?> values, @Nullable QueryShardContext context) { BooleanQuery.Builder builder = new BooleanQuery.Builder(); for (Object value : values) { builder.add(termQuery(value, context), Occur.SHOULD); } return new ConstantScoreQuery(builder.build()); }
Query query; try { query = ft.fieldType.termQuery(term, context); } catch (IllegalArgumentException e) {
private long getBackgroundFrequency(String value) throws IOException { Query query = fieldType.termQuery(value, context.getQueryShardContext()); if (query instanceof TermQuery) { // for types that use the inverted index, we prefer using a caching terms // enum that will do a better job at reusing index inputs Term term = ((TermQuery) query).getTerm(); FilterableTermsEnum termsEnum = getTermsEnum(term.field()); if (termsEnum.seekExact(term.bytes())) { return termsEnum.docFreq(); } else { return 0; } } // otherwise do it the naive way if (filter != null) { query = new BooleanQuery.Builder() .add(query, Occur.FILTER) .add(filter, Occur.FILTER) .build(); } return context.searcher().count(query); }
private long getBackgroundFrequency(String value) throws IOException { Query query = fieldType.termQuery(value, context.getQueryShardContext()); if (query instanceof TermQuery) { // for types that use the inverted index, we prefer using a caching terms // enum that will do a better job at reusing index inputs Term term = ((TermQuery) query).getTerm(); FilterableTermsEnum termsEnum = getTermsEnum(term.field()); if (termsEnum.seekExact(term.bytes())) { return termsEnum.docFreq(); } else { return 0; } } // otherwise do it the naive way if (filter != null) { query = new BooleanQuery.Builder() .add(query, Occur.FILTER) .add(filter, Occur.FILTER) .build(); } return context.searcher().count(query); }
public Query nullValueQuery() { if (nullValue == null) { return null; } return new ConstantScoreQuery(termQuery(nullValue, null)); }
@Override protected Query doToQuery(QueryShardContext context) throws IOException { Query query = null; MappedFieldType mapper = context.fieldMapper(this.fieldName); if (mapper != null) { query = mapper.termQuery(this.value, context); } if (query == null) { query = new TermQuery(new Term(this.fieldName, BytesRefs.toBytesRef(this.value))); } return query; }
@Override protected Query doToQuery(QueryShardContext context) throws IOException { Query query = null; MappedFieldType mapper = context.fieldMapper(this.fieldName); if (mapper != null) { query = mapper.termQuery(this.value, context); } if (query == null) { query = new TermQuery(new Term(this.fieldName, BytesRefs.toBytesRef(this.value))); } return query; }
@Override protected SpanQuery doToQuery(QueryShardContext context) throws IOException { MappedFieldType mapper = context.fieldMapper(fieldName); Term term; if (mapper == null) { term = new Term(fieldName, BytesRefs.toBytesRef(value)); } else { Query termQuery = mapper.termQuery(value, context); term = MappedFieldType.extractTerm(termQuery); } return new SpanTermQuery(term); }
@Override protected SpanQuery doToQuery(QueryShardContext context) throws IOException { MappedFieldType mapper = context.fieldMapper(fieldName); Term term; if (mapper == null) { term = new Term(fieldName, BytesRefs.toBytesRef(value)); } else { Query termQuery = mapper.termQuery(value, context); term = MappedFieldType.extractTerm(termQuery); } return new SpanTermQuery(term); }
/** Build a constant-scoring query that matches all values. The default implementation uses a * {@link ConstantScoreQuery} around a {@link BooleanQuery} whose {@link Occur#SHOULD} clauses * are generated with {@link #termQuery}. */ public Query termsQuery(List<?> values, @Nullable QueryShardContext context) { BooleanQuery.Builder builder = new BooleanQuery.Builder(); for (Object value : values) { builder.add(termQuery(value, context), Occur.SHOULD); } return new ConstantScoreQuery(builder.build()); }
/** Build a constant-scoring query that matches all values. The default implementation uses a * {@link ConstantScoreQuery} around a {@link BooleanQuery} whose {@link Occur#SHOULD} clauses * are generated with {@link #termQuery}. */ public Query termsQuery(List<?> values, @Nullable QueryShardContext context) { BooleanQuery.Builder builder = new BooleanQuery.Builder(); for (Object value : values) { builder.add(termQuery(value, context), Occur.SHOULD); } return new ConstantScoreQuery(builder.build()); }
@Override protected Query newTermQuery(Term term) { MappedFieldType currentFieldType = context.fieldMapper(term.field()); if (currentFieldType == null || currentFieldType.tokenized()) { return super.newTermQuery(term); } return currentFieldType.termQuery(term.bytes(), context); }