Usages of

org.apache.lucene.queries.ExtendedCommonTermsQuery.setBoost(?)
@Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { XContentParser parser = parseContext.parser(); XContentParser.Token token = parser.nextToken(); if (token != XContentParser.Token.FIELD_NAME) { throw new QueryParsingException(parseContext, "[common] query malformed, no field"); } String fieldName = parser.currentName(); Object value = null; float boost = 1.0f; String queryAnalyzer = null; String lowFreqMinimumShouldMatch = null; String highFreqMinimumShouldMatch = null; boolean disableCoords = DEFAULT_DISABLE_COORDS; Occur highFreqOccur = DEFAULT_HIGH_FREQ_OCCUR; Occur lowFreqOccur = DEFAULT_LOW_FREQ_OCCUR; float maxTermFrequency = DEFAULT_MAX_TERM_DOC_FREQ; String queryName = null; token = parser.nextToken(); if (token == XContentParser.Token.START_OBJECT) { String currentFieldName = null; 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 ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { String innerFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { innerFieldName = parser.currentName(); } else if (token.isValue()) { if ("low_freq".equals(innerFieldName) || "lowFreq".equals(innerFieldName)) { lowFreqMinimumShouldMatch = parser.text(); } else if ("high_freq".equals(innerFieldName) || "highFreq".equals(innerFieldName)) { highFreqMinimumShouldMatch = parser.text(); } else { throw new QueryParsingException(parseContext, "[common] query does not support [" + innerFieldName + "] for [" + currentFieldName + "]"); } } } } else { throw new QueryParsingException(parseContext, "[common] query does not support [" + currentFieldName + "]"); } } else if (token.isValue()) { if ("query".equals(currentFieldName)) { value = parser.objectText(); } else if ("analyzer".equals(currentFieldName)) { String analyzer = parser.text(); if (parseContext.analysisService().analyzer(analyzer) == null) { throw new QueryParsingException(parseContext, "[common] analyzer [" + parser.text() + "] not found"); } queryAnalyzer = analyzer; } else if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) { disableCoords = parser.booleanValue(); } else if ("boost".equals(currentFieldName)) { boost = parser.floatValue(); } else if ("high_freq_operator".equals(currentFieldName) || "highFreqOperator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.MUST; } else { throw new QueryParsingException(parseContext, "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("low_freq_operator".equals(currentFieldName) || "lowFreqOperator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.MUST; } else { throw new QueryParsingException(parseContext, "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { lowFreqMinimumShouldMatch = parser.text(); } else if ("cutoff_frequency".equals(currentFieldName)) { maxTermFrequency = parser.floatValue(); } else if ("_name".equals(currentFieldName)) { queryName = parser.text(); } else { throw new QueryParsingException(parseContext, "[common] query does not support [" + currentFieldName + "]"); } } } parser.nextToken(); } else { value = parser.objectText(); // move to the next token token = parser.nextToken(); if (token != XContentParser.Token.END_OBJECT) { throw new QueryParsingException( parseContext, "[common] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?"); } } if (value == null) { throw new QueryParsingException(parseContext, "No text specified for text query"); } String field; FieldMapper mapper = parseContext.fieldMapper(fieldName); if (mapper != null) { field = mapper.fieldType().names().indexName(); } else { field = fieldName; } Analyzer analyzer = null; if (queryAnalyzer == null) { if (mapper != null) { analyzer = mapper.fieldType().searchAnalyzer(); } if (analyzer == null && mapper != null) { analyzer = parseContext.getSearchAnalyzer(mapper); } if (analyzer == null) { analyzer = parseContext.mapperService().searchAnalyzer(); } } else { analyzer = parseContext.mapperService().analysisService().analyzer(queryAnalyzer); if (analyzer == null) { throw new IllegalArgumentException("No analyzer found for [" + queryAnalyzer + "]"); } } ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency, disableCoords, mapper); commonsQuery.setBoost(boost); Query query = parseQueryString(commonsQuery, value.toString(), field, parseContext, analyzer, lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch); if (queryName != null) { parseContext.addNamedQuery(queryName, query); } return query; }
@Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { XContentParser parser = parseContext.parser(); XContentParser.Token token = parser.nextToken(); if (token != XContentParser.Token.FIELD_NAME) { throw new QueryParsingException(parseContext, "[common] query malformed, no field"); } String fieldName = parser.currentName(); Object value = null; float boost = 1.0f; String queryAnalyzer = null; String lowFreqMinimumShouldMatch = null; String highFreqMinimumShouldMatch = null; boolean disableCoords = DEFAULT_DISABLE_COORDS; Occur highFreqOccur = DEFAULT_HIGH_FREQ_OCCUR; Occur lowFreqOccur = DEFAULT_LOW_FREQ_OCCUR; float maxTermFrequency = DEFAULT_MAX_TERM_DOC_FREQ; String queryName = null; token = parser.nextToken(); if (token == XContentParser.Token.START_OBJECT) { String currentFieldName = null; 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 ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { String innerFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { innerFieldName = parser.currentName(); } else if (token.isValue()) { if ("low_freq".equals(innerFieldName) || "lowFreq".equals(innerFieldName)) { lowFreqMinimumShouldMatch = parser.text(); } else if ("high_freq".equals(innerFieldName) || "highFreq".equals(innerFieldName)) { highFreqMinimumShouldMatch = parser.text(); } else { throw new QueryParsingException(parseContext, "[common] query does not support [" + innerFieldName + "] for [" + currentFieldName + "]"); } } } } else { throw new QueryParsingException(parseContext, "[common] query does not support [" + currentFieldName + "]"); } } else if (token.isValue()) { if ("query".equals(currentFieldName)) { value = parser.objectText(); } else if ("analyzer".equals(currentFieldName)) { String analyzer = parser.text(); if (parseContext.analysisService().analyzer(analyzer) == null) { throw new QueryParsingException(parseContext, "[common] analyzer [" + parser.text() + "] not found"); } queryAnalyzer = analyzer; } else if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) { disableCoords = parser.booleanValue(); } else if ("boost".equals(currentFieldName)) { boost = parser.floatValue(); } else if ("high_freq_operator".equals(currentFieldName) || "highFreqOperator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.MUST; } else { throw new QueryParsingException(parseContext, "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("low_freq_operator".equals(currentFieldName) || "lowFreqOperator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.MUST; } else { throw new QueryParsingException(parseContext, "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { lowFreqMinimumShouldMatch = parser.text(); } else if ("cutoff_frequency".equals(currentFieldName)) { maxTermFrequency = parser.floatValue(); } else if ("_name".equals(currentFieldName)) { queryName = parser.text(); } else { throw new QueryParsingException(parseContext, "[common] query does not support [" + currentFieldName + "]"); } } } parser.nextToken(); } else { value = parser.objectText(); // move to the next token token = parser.nextToken(); if (token != XContentParser.Token.END_OBJECT) { throw new QueryParsingException( parseContext, "[common] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?"); } } if (value == null) { throw new QueryParsingException(parseContext, "No text specified for text query"); } String field; MappedFieldType fieldType = parseContext.fieldMapper(fieldName); if (fieldType != null) { field = fieldType.names().indexName(); } else { field = fieldName; } Analyzer analyzer = null; if (queryAnalyzer == null) { if (fieldType != null) { analyzer = fieldType.searchAnalyzer(); } if (analyzer == null && fieldType != null) { analyzer = parseContext.getSearchAnalyzer(fieldType); } if (analyzer == null) { analyzer = parseContext.mapperService().searchAnalyzer(); } } else { analyzer = parseContext.mapperService().analysisService().analyzer(queryAnalyzer); if (analyzer == null) { throw new IllegalArgumentException("No analyzer found for [" + queryAnalyzer + "]"); } } ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency, disableCoords, fieldType); commonsQuery.setBoost(boost); Query query = parseQueryString(commonsQuery, value.toString(), field, parseContext, analyzer, lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch); if (queryName != null) { parseContext.addNamedQuery(queryName, query); } return query; }
@Override public Query parse(QueryParseContext parseContext) throws IOException, ParsingException { XContentParser parser = parseContext.parser(); XContentParser.Token token = parser.nextToken(); if (token != XContentParser.Token.FIELD_NAME) { throw new ParsingException(parseContext, "[common] query malformed, no field"); } String fieldName = parser.currentName(); Object value = null; float boost = 1.0f; String queryAnalyzer = null; String lowFreqMinimumShouldMatch = null; String highFreqMinimumShouldMatch = null; boolean disableCoord = DEFAULT_DISABLE_COORD; Occur highFreqOccur = DEFAULT_HIGH_FREQ_OCCUR; Occur lowFreqOccur = DEFAULT_LOW_FREQ_OCCUR; float maxTermFrequency = DEFAULT_MAX_TERM_DOC_FREQ; String queryName = null; token = parser.nextToken(); if (token == XContentParser.Token.START_OBJECT) { String currentFieldName = null; 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 ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { String innerFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { innerFieldName = parser.currentName(); } else if (token.isValue()) { if ("low_freq".equals(innerFieldName) || "lowFreq".equals(innerFieldName)) { lowFreqMinimumShouldMatch = parser.text(); } else if ("high_freq".equals(innerFieldName) || "highFreq".equals(innerFieldName)) { highFreqMinimumShouldMatch = parser.text(); } else { throw new ParsingException(parseContext, "[common] query does not support [" + innerFieldName + "] for [" + currentFieldName + "]"); } } } } else { throw new ParsingException(parseContext, "[common] query does not support [" + currentFieldName + "]"); } } else if (token.isValue()) { if ("query".equals(currentFieldName)) { value = parser.objectText(); } else if ("analyzer".equals(currentFieldName)) { String analyzer = parser.text(); if (parseContext.analysisService().analyzer(analyzer) == null) { throw new ParsingException(parseContext, "[common] analyzer [" + parser.text() + "] not found"); } queryAnalyzer = analyzer; } else if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) { disableCoord = parser.booleanValue(); } else if ("boost".equals(currentFieldName)) { boost = parser.floatValue(); } else if ("high_freq_operator".equals(currentFieldName) || "highFreqOperator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.MUST; } else { throw new ParsingException(parseContext, "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("low_freq_operator".equals(currentFieldName) || "lowFreqOperator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.MUST; } else { throw new ParsingException(parseContext, "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { lowFreqMinimumShouldMatch = parser.text(); } else if ("cutoff_frequency".equals(currentFieldName)) { maxTermFrequency = parser.floatValue(); } else if ("_name".equals(currentFieldName)) { queryName = parser.text(); } else { throw new ParsingException(parseContext, "[common] query does not support [" + currentFieldName + "]"); } } } parser.nextToken(); } else { value = parser.objectText(); // move to the next token token = parser.nextToken(); if (token != XContentParser.Token.END_OBJECT) { throw new ParsingException( parseContext, "[common] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?"); } } if (value == null) { throw new ParsingException(parseContext, "No text specified for text query"); } String field; MappedFieldType fieldType = parseContext.fieldMapper(fieldName); if (fieldType != null) { field = fieldType.names().indexName(); } else { field = fieldName; } Analyzer analyzer = null; if (queryAnalyzer == null) { if (fieldType != null) { analyzer = fieldType.searchAnalyzer(); } if (analyzer == null && fieldType != null) { analyzer = parseContext.getSearchAnalyzer(fieldType); } if (analyzer == null) { analyzer = parseContext.mapperService().searchAnalyzer(); } } else { analyzer = parseContext.mapperService().analysisService().analyzer(queryAnalyzer); if (analyzer == null) { throw new IllegalArgumentException("No analyzer found for [" + queryAnalyzer + "]"); } } ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency, disableCoord, fieldType); commonsQuery.setBoost(boost); Query query = parseQueryString(commonsQuery, value.toString(), field, parseContext, analyzer, lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch); if (queryName != null) { parseContext.addNamedQuery(queryName, query); } return query; }
@Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { XContentParser parser = parseContext.parser(); XContentParser.Token token = parser.nextToken(); if (token != XContentParser.Token.FIELD_NAME) { throw new QueryParsingException(parseContext, "[common] query malformed, no field"); } String fieldName = parser.currentName(); Object value = null; float boost = 1.0f; String queryAnalyzer = null; String lowFreqMinimumShouldMatch = null; String highFreqMinimumShouldMatch = null; boolean disableCoord = DEFAULT_DISABLE_COORD; Occur highFreqOccur = DEFAULT_HIGH_FREQ_OCCUR; Occur lowFreqOccur = DEFAULT_LOW_FREQ_OCCUR; float maxTermFrequency = DEFAULT_MAX_TERM_DOC_FREQ; String queryName = null; token = parser.nextToken(); if (token == XContentParser.Token.START_OBJECT) { String currentFieldName = null; 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 ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { String innerFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { innerFieldName = parser.currentName(); } else if (token.isValue()) { if ("low_freq".equals(innerFieldName) || "lowFreq".equals(innerFieldName)) { lowFreqMinimumShouldMatch = parser.text(); } else if ("high_freq".equals(innerFieldName) || "highFreq".equals(innerFieldName)) { highFreqMinimumShouldMatch = parser.text(); } else { throw new QueryParsingException(parseContext, "[common] query does not support [" + innerFieldName + "] for [" + currentFieldName + "]"); } } } } else { throw new QueryParsingException(parseContext, "[common] query does not support [" + currentFieldName + "]"); } } else if (token.isValue()) { if ("query".equals(currentFieldName)) { value = parser.objectText(); } else if ("analyzer".equals(currentFieldName)) { String analyzer = parser.text(); if (parseContext.analysisService().analyzer(analyzer) == null) { throw new QueryParsingException(parseContext, "[common] analyzer [" + parser.text() + "] not found"); } queryAnalyzer = analyzer; } else if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) { disableCoord = parser.booleanValue(); } else if ("boost".equals(currentFieldName)) { boost = parser.floatValue(); } else if ("high_freq_operator".equals(currentFieldName) || "highFreqOperator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.MUST; } else { throw new QueryParsingException(parseContext, "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("low_freq_operator".equals(currentFieldName) || "lowFreqOperator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.MUST; } else { throw new QueryParsingException(parseContext, "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { lowFreqMinimumShouldMatch = parser.text(); } else if ("cutoff_frequency".equals(currentFieldName)) { maxTermFrequency = parser.floatValue(); } else if ("_name".equals(currentFieldName)) { queryName = parser.text(); } else { throw new QueryParsingException(parseContext, "[common] query does not support [" + currentFieldName + "]"); } } } parser.nextToken(); } else { value = parser.objectText(); // move to the next token token = parser.nextToken(); if (token != XContentParser.Token.END_OBJECT) { throw new QueryParsingException( parseContext, "[common] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?"); } } if (value == null) { throw new QueryParsingException(parseContext, "No text specified for text query"); } String field; MappedFieldType fieldType = parseContext.fieldMapper(fieldName); if (fieldType != null) { field = fieldType.names().indexName(); } else { field = fieldName; } Analyzer analyzer = null; if (queryAnalyzer == null) { if (fieldType != null) { analyzer = fieldType.searchAnalyzer(); } if (analyzer == null && fieldType != null) { analyzer = parseContext.getSearchAnalyzer(fieldType); } if (analyzer == null) { analyzer = parseContext.mapperService().searchAnalyzer(); } } else { analyzer = parseContext.mapperService().analysisService().analyzer(queryAnalyzer); if (analyzer == null) { throw new IllegalArgumentException("No analyzer found for [" + queryAnalyzer + "]"); } } ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency, disableCoord, fieldType); commonsQuery.setBoost(boost); Query query = parseQueryString(commonsQuery, value.toString(), field, parseContext, analyzer, lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch); if (queryName != null) { parseContext.addNamedQuery(queryName, query); } return query; }
@Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { XContentParser parser = parseContext.parser(); XContentParser.Token token = parser.nextToken(); if (token != XContentParser.Token.FIELD_NAME) { throw new QueryParsingException(parseContext.index(), "[common] query malformed, no field"); } String fieldName = parser.currentName(); Object value = null; float boost = 1.0f; String queryAnalyzer = null; String minimumShouldMatch = null; boolean disableCoords = DEFAULT_DISABLE_COORDS; Occur highFreqOccur = DEFAULT_HIGH_FREQ_OCCUR; Occur lowFreqOccur = DEFAULT_HIGH_FREQ_OCCUR; float maxTermFrequency = DEFAULT_MAX_TERM_DOC_FREQ; token = parser.nextToken(); if (token == XContentParser.Token.START_OBJECT) { String currentFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if ("query".equals(currentFieldName)) { value = parser.objectText(); } else if ("analyzer".equals(currentFieldName)) { String analyzer = parser.text(); if (parseContext.analysisService().analyzer(analyzer) == null) { throw new QueryParsingException(parseContext.index(), "[common] analyzer [" + parser.text() + "] not found"); } queryAnalyzer = analyzer; } else if ("disable_coords".equals(currentFieldName)) { disableCoords = parser.booleanValue(); } else if ("boost".equals(currentFieldName)) { boost = parser.floatValue(); } else if ("high_freq_operator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.MUST; } else { throw new QueryParsingException(parseContext.index(), "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("low_freq_operator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.MUST; } else { throw new QueryParsingException(parseContext.index(), "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { minimumShouldMatch = parser.textOrNull(); } else if ("cutoff_frequency".equals(currentFieldName)) { maxTermFrequency = parser.floatValue(); } else { throw new QueryParsingException(parseContext.index(), "[common] query does not support [" + currentFieldName + "]"); } } } parser.nextToken(); } else { value = parser.objectText(); // move to the next token token = parser.nextToken(); if (token != XContentParser.Token.END_OBJECT) { throw new QueryParsingException( parseContext.index(), "[common] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?"); } } if (value == null) { throw new QueryParsingException(parseContext.index(), "No text specified for text query"); } ExtendedCommonTermsQuery query = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency, disableCoords); query.setBoost(boost); return parseQueryString(query, value.toString(), fieldName, parseContext, queryAnalyzer, minimumShouldMatch); }
@Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { XContentParser parser = parseContext.parser(); XContentParser.Token token = parser.nextToken(); if (token != XContentParser.Token.FIELD_NAME) { throw new QueryParsingException(parseContext.index(), "[common] query malformed, no field"); } String fieldName = parser.currentName(); Object value = null; float boost = 1.0f; String queryAnalyzer = null; String lowFreqMinimumShouldMatch = null; String highFreqMinimumShouldMatch = null; boolean disableCoord = DEFAULT_DISABLE_COORD; Occur highFreqOccur = DEFAULT_HIGH_FREQ_OCCUR; Occur lowFreqOccur = DEFAULT_LOW_FREQ_OCCUR; float maxTermFrequency = DEFAULT_MAX_TERM_DOC_FREQ; String queryName = null; token = parser.nextToken(); if (token == XContentParser.Token.START_OBJECT) { String currentFieldName = null; 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 ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { String innerFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { innerFieldName = parser.currentName(); } else if (token.isValue()) { if ("low_freq".equals(innerFieldName) || "lowFreq".equals(innerFieldName)) { lowFreqMinimumShouldMatch = parser.text(); } else if ("high_freq".equals(innerFieldName) || "highFreq".equals(innerFieldName)) { highFreqMinimumShouldMatch = parser.text(); } else { throw new QueryParsingException(parseContext.index(), "[common] query does not support [" + innerFieldName + "] for [" + currentFieldName + "]"); } } } } else { throw new QueryParsingException(parseContext.index(), "[common] query does not support [" + currentFieldName + "]"); } } else if (token.isValue()) { if ("query".equals(currentFieldName)) { value = parser.objectText(); } else if ("analyzer".equals(currentFieldName)) { String analyzer = parser.text(); if (parseContext.analysisService().analyzer(analyzer) == null) { throw new QueryParsingException(parseContext.index(), "[common] analyzer [" + parser.text() + "] not found"); } queryAnalyzer = analyzer; } else if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) { disableCoord = parser.booleanValue(); } else if ("boost".equals(currentFieldName)) { boost = parser.floatValue(); } else if ("high_freq_operator".equals(currentFieldName) || "highFreqOperator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.MUST; } else { throw new QueryParsingException(parseContext.index(), "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("low_freq_operator".equals(currentFieldName) || "lowFreqOperator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.MUST; } else { throw new QueryParsingException(parseContext.index(), "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { lowFreqMinimumShouldMatch = parser.text(); } else if ("cutoff_frequency".equals(currentFieldName)) { maxTermFrequency = parser.floatValue(); } else if ("_name".equals(currentFieldName)) { queryName = parser.text(); } else { throw new QueryParsingException(parseContext.index(), "[common] query does not support [" + currentFieldName + "]"); } } } parser.nextToken(); } else { value = parser.objectText(); // move to the next token token = parser.nextToken(); if (token != XContentParser.Token.END_OBJECT) { throw new QueryParsingException( parseContext.index(), "[common] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?"); } } if (value == null) { throw new QueryParsingException(parseContext.index(), "No text specified for text query"); } FieldMapper<?> mapper = null; String field; MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName); if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) { mapper = smartNameFieldMappers.mapper(); field = mapper.names().indexName(); } else { field = fieldName; } Analyzer analyzer = null; if (queryAnalyzer == null) { if (mapper != null) { analyzer = mapper.searchAnalyzer(); } if (analyzer == null && smartNameFieldMappers != null) { analyzer = smartNameFieldMappers.searchAnalyzer(); } if (analyzer == null) { analyzer = parseContext.mapperService().searchAnalyzer(); } } else { analyzer = parseContext.mapperService().analysisService().analyzer(queryAnalyzer); if (analyzer == null) { throw new ElasticsearchIllegalArgumentException("No analyzer found for [" + queryAnalyzer + "]"); } } ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency, disableCoord, mapper); commonsQuery.setBoost(boost); Query query = parseQueryString(commonsQuery, value.toString(), field, parseContext, analyzer, lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch, smartNameFieldMappers); if (queryName != null) { parseContext.addNamedQuery(queryName, query); } return query; }
@Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { XContentParser parser = parseContext.parser(); XContentParser.Token token = parser.nextToken(); if (token != XContentParser.Token.FIELD_NAME) { throw new QueryParsingException(parseContext.index(), "[common] query malformed, no field"); } String fieldName = parser.currentName(); Object value = null; float boost = 1.0f; String queryAnalyzer = null; String lowFreqMinimumShouldMatch = null; String highFreqMinimumShouldMatch = null; boolean disableCoords = DEFAULT_DISABLE_COORDS; Occur highFreqOccur = DEFAULT_HIGH_FREQ_OCCUR; Occur lowFreqOccur = DEFAULT_LOW_FREQ_OCCUR; float maxTermFrequency = DEFAULT_MAX_TERM_DOC_FREQ; String queryName = null; token = parser.nextToken(); if (token == XContentParser.Token.START_OBJECT) { String currentFieldName = null; 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 ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { String innerFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { innerFieldName = parser.currentName(); } else if (token.isValue()) { if ("low_freq".equals(innerFieldName) || "lowFreq".equals(innerFieldName)) { lowFreqMinimumShouldMatch = parser.text(); } else if ("high_freq".equals(innerFieldName) || "highFreq".equals(innerFieldName)) { highFreqMinimumShouldMatch = parser.text(); } else { throw new QueryParsingException(parseContext.index(), "[common] query does not support [" + innerFieldName + "] for [" + currentFieldName + "]"); } } } } else { throw new QueryParsingException(parseContext.index(), "[common] query does not support [" + currentFieldName + "]"); } } else if (token.isValue()) { if ("query".equals(currentFieldName)) { value = parser.objectText(); } else if ("analyzer".equals(currentFieldName)) { String analyzer = parser.text(); if (parseContext.analysisService().analyzer(analyzer) == null) { throw new QueryParsingException(parseContext.index(), "[common] analyzer [" + parser.text() + "] not found"); } queryAnalyzer = analyzer; } else if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) { disableCoords = parser.booleanValue(); } else if ("boost".equals(currentFieldName)) { boost = parser.floatValue(); } else if ("high_freq_operator".equals(currentFieldName) || "highFreqOperator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.MUST; } else { throw new QueryParsingException(parseContext.index(), "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("low_freq_operator".equals(currentFieldName) || "lowFreqOperator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.MUST; } else { throw new QueryParsingException(parseContext.index(), "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { lowFreqMinimumShouldMatch = parser.text(); } else if ("cutoff_frequency".equals(currentFieldName)) { maxTermFrequency = parser.floatValue(); } else if ("_name".equals(currentFieldName)) { queryName = parser.text(); } else { throw new QueryParsingException(parseContext.index(), "[common] query does not support [" + currentFieldName + "]"); } } } parser.nextToken(); } else { value = parser.objectText(); // move to the next token token = parser.nextToken(); if (token != XContentParser.Token.END_OBJECT) { throw new QueryParsingException( parseContext.index(), "[common] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?"); } } if (value == null) { throw new QueryParsingException(parseContext.index(), "No text specified for text query"); } FieldMapper<?> mapper = null; String field; MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName); if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) { mapper = smartNameFieldMappers.mapper(); field = mapper.names().indexName(); } else { field = fieldName; } Analyzer analyzer = null; if (queryAnalyzer == null) { if (mapper != null) { analyzer = mapper.searchAnalyzer(); } if (analyzer == null && smartNameFieldMappers != null) { analyzer = smartNameFieldMappers.searchAnalyzer(); } if (analyzer == null) { analyzer = parseContext.mapperService().searchAnalyzer(); } } else { analyzer = parseContext.mapperService().analysisService().analyzer(queryAnalyzer); if (analyzer == null) { throw new ElasticsearchIllegalArgumentException("No analyzer found for [" + queryAnalyzer + "]"); } } ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency, disableCoords, mapper); commonsQuery.setBoost(boost); Query query = parseQueryString(commonsQuery, value.toString(), field, parseContext, analyzer, lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch, smartNameFieldMappers); if (queryName != null) { parseContext.addNamedQuery(queryName, query); } return query; }
@Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { XContentParser parser = parseContext.parser(); XContentParser.Token token = parser.nextToken(); if (token != XContentParser.Token.FIELD_NAME) { throw new QueryParsingException(parseContext.index(), "[common] query malformed, no field"); } String fieldName = parser.currentName(); Object value = null; float boost = 1.0f; String queryAnalyzer = null; String minimumShouldMatch = null; boolean disableCoords = DEFAULT_DISABLE_COORDS; Occur highFreqOccur = DEFAULT_HIGH_FREQ_OCCUR; Occur lowFreqOccur = DEFAULT_HIGH_FREQ_OCCUR; float maxTermFrequency = DEFAULT_MAX_TERM_DOC_FREQ; token = parser.nextToken(); if (token == XContentParser.Token.START_OBJECT) { String currentFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if ("query".equals(currentFieldName)) { value = parser.objectText(); } else if ("analyzer".equals(currentFieldName)) { String analyzer = parser.text(); if (parseContext.analysisService().analyzer(analyzer) == null) { throw new QueryParsingException(parseContext.index(), "[common] analyzer [" + parser.text() + "] not found"); } queryAnalyzer = analyzer; } else if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) { disableCoords = parser.booleanValue(); } else if ("boost".equals(currentFieldName)) { boost = parser.floatValue(); } else if ("high_freq_operator".equals(currentFieldName) || "highFreqOperator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { highFreqOccur = BooleanClause.Occur.MUST; } else { throw new QueryParsingException(parseContext.index(), "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("low_freq_operator".equals(currentFieldName) || "lowFreqOperator".equals(currentFieldName)) { String op = parser.text(); if ("or".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.SHOULD; } else if ("and".equalsIgnoreCase(op)) { lowFreqOccur = BooleanClause.Occur.MUST; } else { throw new QueryParsingException(parseContext.index(), "[common] query requires operator to be either 'and' or 'or', not [" + op + "]"); } } else if ("minimum_should_match".equals(currentFieldName) || "minimumShouldMatch".equals(currentFieldName)) { minimumShouldMatch = parser.textOrNull(); } else if ("cutoff_frequency".equals(currentFieldName)) { maxTermFrequency = parser.floatValue(); } else { throw new QueryParsingException(parseContext.index(), "[common] query does not support [" + currentFieldName + "]"); } } } parser.nextToken(); } else { value = parser.objectText(); // move to the next token token = parser.nextToken(); if (token != XContentParser.Token.END_OBJECT) { throw new QueryParsingException( parseContext.index(), "[common] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?"); } } if (value == null) { throw new QueryParsingException(parseContext.index(), "No text specified for text query"); } ExtendedCommonTermsQuery query = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency, disableCoords); query.setBoost(boost); return parseQueryString(query, value.toString(), fieldName, parseContext, queryAnalyzer, minimumShouldMatch); }
Usage snippet has been bookmarked! Review your bookmarks
Thank you! Review your likes