/** * @param context The query shard context * @param fieldsAndWeights The default fields and weights expansion for query terms */ public QueryStringQueryParser(QueryShardContext context, Map<String, Float> fieldsAndWeights) { this(context, null, fieldsAndWeights, false, context.getMapperService().searchAnalyzer()); }
/** * @param context The query shard context. * @param defaultField The default field for query terms. */ public QueryStringQueryParser(QueryShardContext context, String defaultField) { this(context, defaultField, Collections.emptyMap(), false, context.getMapperService().searchAnalyzer()); }
/** * @param context The query shard context. * @param defaultField The default field for query terms. * @param lenient If set to `true` will cause format based failures (like providing text to a numeric field) to be ignored. */ public QueryStringQueryParser(QueryShardContext context, String defaultField, boolean lenient) { this(context, defaultField, Collections.emptyMap(), lenient, context.getMapperService().searchAnalyzer()); }
/** * @param context The query shard context. * @param fieldsAndWeights The default fields and weights expansion for query terms. * @param lenient If set to `true` will cause format based failures (like providing text to a numeric field) to be ignored. */ public QueryStringQueryParser(QueryShardContext context, Map<String, Float> fieldsAndWeights, boolean lenient) { this(context, null, fieldsAndWeights, lenient, context.getMapperService().searchAnalyzer()); }
/** * Returns the narrowed down explicit types, or, if not set, all types. */ public Collection<String> queryTypes() { String[] types = getTypes(); if (types == null || types.length == 0) { return getMapperService().types(); } if (types.length == 1 && types[0].equals("_all")) { return getMapperService().types(); } return Arrays.asList(types); }
public void setAnalyzer(String analyzerName) { this.analyzer = context.getMapperService().getIndexAnalyzers().get(analyzerName); if (analyzer == null) { throw new IllegalArgumentException("No analyzer found for [" + analyzerName + "]"); } }
public SearchLookup lookup() { if (lookup == null) { lookup = new SearchLookup(getMapperService(), mappedFieldType -> indexFieldDataService.apply(mappedFieldType, fullyQualifiedIndex.getName()), types); } return lookup; }
/** * Defaults to all queryiable fields extracted from the mapping for query terms * @param context The query shard context * @param lenient If set to `true` will cause format based failures (like providing text to a numeric field) to be ignored. */ public QueryStringQueryParser(QueryShardContext context, boolean lenient) { this(context, "*", resolveMappingField(context, "*", 1.0f, false, false), lenient, context.getMapperService().searchAnalyzer()); }
@Override protected Query doToQuery(QueryShardContext context) throws IOException { //LUCENE 4 UPGRADE document mapper should use bytesref as well? DocumentMapper documentMapper = context.getMapperService().documentMapper(type); if (documentMapper == null) { // no type means no documents return new MatchNoDocsQuery(); } else { return documentMapper.typeFilter(context); } }
private Query existsQuery(String fieldName) { final FieldNamesFieldMapper.FieldNamesFieldType fieldNamesFieldType = (FieldNamesFieldMapper.FieldNamesFieldType) context.getMapperService().fullName(FieldNamesFieldMapper.NAME); if (fieldNamesFieldType == null) { return new MatchNoDocsQuery("No mappings yet"); } if (fieldNamesFieldType.isEnabled() == false) { // The field_names_field is disabled so we switch to a wildcard query that matches all terms return new WildcardQuery(new Term(fieldName, "*")); } return ExistsQueryBuilder.newFilter(context, fieldName); }
/** * Gets the search quote analyzer for the given field, or the default if there is none present for the field * TODO: remove this by moving defaults into mappers themselves */ public Analyzer getSearchQuoteAnalyzer(MappedFieldType fieldType) { if (fieldType.searchQuoteAnalyzer() != null) { return fieldType.searchQuoteAnalyzer(); } return getMapperService().searchQuoteAnalyzer(); }
/** * Gets the search analyzer for the given field, or the default if there is none present for the field * TODO: remove this by moving defaults into mappers themselves */ public Analyzer getSearchAnalyzer(MappedFieldType fieldType) { if (fieldType.searchAnalyzer() != null) { return fieldType.searchAnalyzer(); } return getMapperService().searchAnalyzer(); }
@Override protected ScoreFunction doToFunction(QueryShardContext context) { MappedFieldType fieldType = context.getMapperService().fullName(field); IndexNumericFieldData fieldData = null; if (fieldType == null) { if(missing == null) { throw new ElasticsearchException("Unable to find a field mapper for field [" + field + "]. No 'missing' value defined."); } } else { fieldData = context.getForField(fieldType); } return new FieldValueFactorFunction(field, factor, modifier, missing, fieldData); }
@Override protected Query doToQuery(QueryShardContext context) throws IOException { Query query; MappedFieldType uidField = context.fieldMapper(UidFieldMapper.NAME); if (uidField == null) { return new MatchNoDocsQuery("No mappings"); } if (this.ids.isEmpty()) { query = Queries.newMatchNoDocsQuery("Missing ids in \"" + this.getName() + "\" query."); } else { Collection<String> typesForQuery; if (types.length == 0) { typesForQuery = context.queryTypes(); } else if (types.length == 1 && MetaData.ALL.equals(types[0])) { typesForQuery = context.getMapperService().types(); } else { typesForQuery = new HashSet<>(); Collections.addAll(typesForQuery, types); } query = uidField.termsQuery(Arrays.asList(Uid.createUidsForTypesAndIds(typesForQuery, ids)), context); } return query; }
private static Query newFieldExistsQuery(QueryShardContext context, String field) { MappedFieldType fieldType = context.getMapperService().fullName(field); if (fieldType == null) { // The field does not exist as a leaf but could be an object so // check for an object mapper if (context.getObjectMapper(field) != null) { return newObjectFieldExistsQuery(context, field); } return Queries.newMatchNoDocsQuery("No field \"" + field + "\" exists in mappings."); } Query filter = fieldType.existsQuery(context); return new ConstantScoreQuery(filter); }
private static Query newObjectFieldExistsQuery(QueryShardContext context, String objField) { BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder(); Collection<String> fields = context.simpleMatchToIndexNames(objField + ".*"); for (String field : fields) { Query existsQuery = context.getMapperService().fullName(field).existsQuery(context); booleanQuery.add(existsQuery, Occur.SHOULD); } return new ConstantScoreQuery(booleanQuery.build()); }
protected MappedFieldType.Relation getRelation(QueryRewriteContext queryRewriteContext) throws IOException { QueryShardContext shardContext = queryRewriteContext.convertToShardContext(); // If the context is null we are not on the shard and cannot // rewrite so just pretend there is an intersection so that the rewrite is a noop if (shardContext == null || shardContext.getIndexReader() == null) { return MappedFieldType.Relation.INTERSECTS; } final MapperService mapperService = shardContext.getMapperService(); final MappedFieldType fieldType = mapperService.fullName(fieldName); if (fieldType == null) { // no field means we have no values return MappedFieldType.Relation.DISJOINT; } else { DateMathParser dateMathParser = getForceDateParser(); return fieldType.isFieldWithinQuery(shardContext.getIndexReader(), from, to, includeLower, includeUpper, timeZone, dateMathParser, queryRewriteContext); } }
@Override protected Query doToQuery(QueryShardContext context) throws IOException { String field; MappedFieldType fieldType = context.fieldMapper(fieldName); if (fieldType != null) { field = fieldType.name(); } else { field = fieldName; } Analyzer analyzerObj; if (analyzer == null) { if (fieldType != null) { analyzerObj = context.getSearchAnalyzer(fieldType); } else { analyzerObj = context.getMapperService().searchAnalyzer(); } } else { analyzerObj = context.getMapperService().getIndexAnalyzers().get(analyzer); if (analyzerObj == null) { throw new QueryShardException(context, "[common] analyzer [" + analyzer + "] not found"); } } Occur highFreqOccur = highFreqOperator.toBooleanClauseOccur(); Occur lowFreqOccur = lowFreqOperator.toBooleanClauseOccur(); ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, cutoffFrequency, fieldType); return parseQueryString(commonsQuery, text, field, analyzerObj, lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch); }
@Override public SuggestionContext build(QueryShardContext context) throws IOException { CompletionSuggestionContext suggestionContext = new CompletionSuggestionContext(context); // copy over common settings to each suggestion builder final MapperService mapperService = context.getMapperService(); populateCommonFields(mapperService, suggestionContext); suggestionContext.setSkipDuplicates(skipDuplicates); suggestionContext.setFuzzyOptions(fuzzyOptions); suggestionContext.setRegexOptions(regexOptions); if (shardSize != null) { suggestionContext.setShardSize(shardSize); } MappedFieldType mappedFieldType = mapperService.fullName(suggestionContext.getField()); if (mappedFieldType == null || mappedFieldType instanceof CompletionFieldMapper.CompletionFieldType == false) { throw new IllegalArgumentException("Field [" + suggestionContext.getField() + "] is not a completion suggest field"); } if (mappedFieldType instanceof CompletionFieldMapper.CompletionFieldType) { CompletionFieldMapper.CompletionFieldType type = (CompletionFieldMapper.CompletionFieldType) mappedFieldType; suggestionContext.setFieldType(type); if (type.hasContextMappings() && contextBytes != null) { Map<String, List<ContextMapping.InternalQueryContext>> queryContexts = parseContextBytes(contextBytes, context.getXContentRegistry(), type.getContextMappings()); suggestionContext.setQueryContexts(queryContexts); } else if (contextBytes != null) { throw new IllegalArgumentException("suggester [" + type.name() + "] doesn't expect any context"); } } assert suggestionContext.getFieldType() != null : "no completion field type set"; return suggestionContext; }
@Override public SuggestionContext build(QueryShardContext context) throws IOException { TermSuggestionContext suggestionContext = new TermSuggestionContext(context); // copy over common settings to each suggestion builder populateCommonFields(context.getMapperService(), suggestionContext); // Transfers the builder settings to the target TermSuggestionContext DirectSpellcheckerSettings settings = suggestionContext.getDirectSpellCheckerSettings(); settings.accuracy(accuracy); settings.maxEdits(maxEdits); settings.maxInspections(maxInspections); settings.maxTermFreq(maxTermFreq); settings.minDocFreq(minDocFreq); settings.minWordLength(minWordLength); settings.prefixLength(prefixLength); settings.sort(sort); settings.stringDistance(stringDistance.toLucene()); settings.suggestMode(suggestMode.toLucene()); return suggestionContext; }