Usages of

org.apache.lucene.queries.ExtendedCommonTermsQuery.getMaxTermFrequency()
@Override protected void doAssertLuceneQuery(MatchQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { assertThat(query, notNullValue()); if (query instanceof MatchAllDocsQuery) { assertThat(queryBuilder.zeroTermsQuery(), equalTo(ZeroTermsQuery.ALL)); return; } switch (queryBuilder.type()) { case BOOLEAN: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(ExtendedCommonTermsQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class)).or(instanceOf(NumericRangeQuery.class))); break; case PHRASE: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(PhraseQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class)).or(instanceOf(NumericRangeQuery.class))); break; case PHRASE_PREFIX: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(MultiPhrasePrefixQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class)).or(instanceOf(NumericRangeQuery.class))); break; } MappedFieldType fieldType = context.fieldMapper(queryBuilder.fieldName()); if (query instanceof TermQuery && fieldType != null) { String queryValue = queryBuilder.value().toString(); if (queryBuilder.analyzer() == null || queryBuilder.analyzer().equals("simple")) { queryValue = queryValue.toLowerCase(Locale.ROOT); } Query expectedTermQuery = fieldType.termQuery(queryValue, context); assertEquals(expectedTermQuery, query); } if (query instanceof BooleanQuery) { BooleanQuery bq = (BooleanQuery) query; if (queryBuilder.minimumShouldMatch() != null) { // calculate expected minimumShouldMatch value int optionalClauses = 0; for (BooleanClause c : bq.clauses()) { if (c.getOccur() == BooleanClause.Occur.SHOULD) { optionalClauses++; } } int msm = Queries.calculateMinShouldMatch(optionalClauses, queryBuilder.minimumShouldMatch()); assertThat(bq.getMinimumNumberShouldMatch(), equalTo(msm)); } if (queryBuilder.analyzer() == null && queryBuilder.value().toString().length() > 0) { assertEquals(bq.clauses().size(), queryBuilder.value().toString().split(" ").length); } } if (query instanceof ExtendedCommonTermsQuery) { assertTrue(queryBuilder.cutoffFrequency() != null); ExtendedCommonTermsQuery ectq = (ExtendedCommonTermsQuery) query; assertEquals(queryBuilder.cutoffFrequency(), ectq.getMaxTermFrequency(), Float.MIN_VALUE); } if (query instanceof FuzzyQuery) { assertTrue(queryBuilder.fuzziness() != null); FuzzyQuery fuzzyQuery = (FuzzyQuery) query; // depending on analyzer being set or not we can have term lowercased along the way, so to simplify test we just // compare lowercased terms here String originalTermLc = queryBuilder.value().toString().toLowerCase(Locale.ROOT); String actualTermLc = fuzzyQuery.getTerm().text().toLowerCase(Locale.ROOT); Matcher<String> termLcMatcher = equalTo(originalTermLc); if ("false".equals(originalTermLc) || "true".equals(originalTermLc)) { // Booleans become t/f when querying a boolean field termLcMatcher = either(termLcMatcher).or(equalTo(originalTermLc.substring(0, 1))); } assertThat(actualTermLc, termLcMatcher); assertThat(queryBuilder.prefixLength(), equalTo(fuzzyQuery.getPrefixLength())); assertThat(queryBuilder.fuzzyTranspositions(), equalTo(fuzzyQuery.getTranspositions())); } if (query instanceof NumericRangeQuery) { // These are fuzzy numeric queries assertTrue(queryBuilder.fuzziness() != null); @SuppressWarnings("unchecked") NumericRangeQuery<Number> numericRangeQuery = (NumericRangeQuery<Number>) query; assertTrue(numericRangeQuery.includesMin()); assertTrue(numericRangeQuery.includesMax()); double value; double width = 0; try { value = Double.parseDouble(queryBuilder.value().toString()); } catch (NumberFormatException e) { // Maybe its a date value = ISODateTimeFormat.dateTimeParser().parseMillis(queryBuilder.value().toString()); width = queryBuilder.fuzziness().asTimeValue().getMillis(); } if (width == 0) { if (queryBuilder.fuzziness().equals(Fuzziness.AUTO)) { width = 1; } else { width = queryBuilder.fuzziness().asDouble(); } } assertEquals(value - width, numericRangeQuery.getMin().doubleValue(), width * .1); assertEquals(value + width, numericRangeQuery.getMax().doubleValue(), width * .1); } }
@Override protected void doAssertLuceneQuery(MatchQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { assertThat(query, notNullValue()); if (query instanceof MatchAllDocsQuery) { assertThat(queryBuilder.zeroTermsQuery(), equalTo(ZeroTermsQuery.ALL)); return; } switch (queryBuilder.type()) { case BOOLEAN: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(ExtendedCommonTermsQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class))); break; case PHRASE: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(PhraseQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class))); break; case PHRASE_PREFIX: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(MultiPhrasePrefixQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class))); break; } MappedFieldType fieldType = context.fieldMapper(queryBuilder.fieldName()); if (query instanceof TermQuery && fieldType != null) { String queryValue = queryBuilder.value().toString(); if (queryBuilder.analyzer() == null || queryBuilder.analyzer().equals("simple")) { queryValue = queryValue.toLowerCase(Locale.ROOT); } Query expectedTermQuery = fieldType.termQuery(queryValue, context); // the real query will have boost applied, so we set it to our expeced as well expectedTermQuery.setBoost(queryBuilder.boost()); assertEquals(expectedTermQuery, query); } if (query instanceof BooleanQuery) { BooleanQuery bq = (BooleanQuery) query; if (queryBuilder.minimumShouldMatch() != null) { // calculate expected minimumShouldMatch value int optionalClauses = 0; for (BooleanClause c : bq.clauses()) { if (c.getOccur() == BooleanClause.Occur.SHOULD) { optionalClauses++; } } int msm = Queries.calculateMinShouldMatch(optionalClauses, queryBuilder.minimumShouldMatch()); assertThat(bq.getMinimumNumberShouldMatch(), equalTo(msm)); } if (queryBuilder.analyzer() == null && queryBuilder.value().toString().length() > 0) { assertEquals(bq.clauses().size(), queryBuilder.value().toString().split(" ").length); } } if (query instanceof ExtendedCommonTermsQuery) { assertTrue(queryBuilder.cutoffFrequency() != null); ExtendedCommonTermsQuery ectq = (ExtendedCommonTermsQuery) query; assertEquals(queryBuilder.cutoffFrequency(), ectq.getMaxTermFrequency(), Float.MIN_VALUE); } if (query instanceof FuzzyQuery) { assertTrue(queryBuilder.fuzziness() != null); FuzzyQuery fuzzyQuery = (FuzzyQuery) query; // depending on analyzer being set or not we can have term lowercased along the way, so to simplify test we just // compare lowercased terms here String originalTermLc = queryBuilder.value().toString().toLowerCase(Locale.ROOT); String actualTermLc = fuzzyQuery.getTerm().text().toString().toLowerCase(Locale.ROOT); assertThat(actualTermLc, equalTo(originalTermLc)); assertThat(queryBuilder.prefixLength(), equalTo(fuzzyQuery.getPrefixLength())); assertThat(queryBuilder.fuzzyTranspositions(), equalTo(fuzzyQuery.getTranspositions())); } }
@Override protected void doAssertLuceneQuery(MatchQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { assertThat(query, notNullValue()); if (query instanceof MatchAllDocsQuery) { assertThat(queryBuilder.zeroTermsQuery(), equalTo(ZeroTermsQuery.ALL)); return; } switch (queryBuilder.type()) { case BOOLEAN: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(ExtendedCommonTermsQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class))); break; case PHRASE: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(PhraseQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class))); break; case PHRASE_PREFIX: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(MultiPhrasePrefixQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class))); break; } MappedFieldType fieldType = context.fieldMapper(queryBuilder.fieldName()); if (query instanceof TermQuery && fieldType != null) { String queryValue = queryBuilder.value().toString(); if (queryBuilder.analyzer() == null || queryBuilder.analyzer().equals("simple")) { queryValue = queryValue.toLowerCase(Locale.ROOT); } Query expectedTermQuery = fieldType.termQuery(queryValue, context); assertEquals(expectedTermQuery, query); } if (query instanceof BooleanQuery) { BooleanQuery bq = (BooleanQuery) query; if (queryBuilder.minimumShouldMatch() != null) { // calculate expected minimumShouldMatch value int optionalClauses = 0; for (BooleanClause c : bq.clauses()) { if (c.getOccur() == BooleanClause.Occur.SHOULD) { optionalClauses++; } } int msm = Queries.calculateMinShouldMatch(optionalClauses, queryBuilder.minimumShouldMatch()); assertThat(bq.getMinimumNumberShouldMatch(), equalTo(msm)); } if (queryBuilder.analyzer() == null && queryBuilder.value().toString().length() > 0) { assertEquals(bq.clauses().size(), queryBuilder.value().toString().split(" ").length); } } if (query instanceof ExtendedCommonTermsQuery) { assertTrue(queryBuilder.cutoffFrequency() != null); ExtendedCommonTermsQuery ectq = (ExtendedCommonTermsQuery) query; assertEquals(queryBuilder.cutoffFrequency(), ectq.getMaxTermFrequency(), Float.MIN_VALUE); } if (query instanceof FuzzyQuery) { assertTrue(queryBuilder.fuzziness() != null); FuzzyQuery fuzzyQuery = (FuzzyQuery) query; // depending on analyzer being set or not we can have term lowercased along the way, so to simplify test we just // compare lowercased terms here String originalTermLc = queryBuilder.value().toString().toLowerCase(Locale.ROOT); String actualTermLc = fuzzyQuery.getTerm().text().toLowerCase(Locale.ROOT); assertThat(actualTermLc, equalTo(originalTermLc)); assertThat(queryBuilder.prefixLength(), equalTo(fuzzyQuery.getPrefixLength())); assertThat(queryBuilder.fuzzyTranspositions(), equalTo(fuzzyQuery.getTranspositions())); } }
@Override protected void doAssertLuceneQuery(MatchQueryBuilder queryBuilder, Query query, SearchContext searchContext) throws IOException { assertThat(query, notNullValue()); if (query instanceof MatchAllDocsQuery) { assertThat(queryBuilder.zeroTermsQuery(), equalTo(ZeroTermsQuery.ALL)); return; } switch (queryBuilder.type()) { case BOOLEAN: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(ExtendedCommonTermsQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class)).or(instanceOf(MatchNoDocsQuery.class)) .or(instanceOf(PointRangeQuery.class)).or(instanceOf(IndexOrDocValuesQuery.class))); break; case PHRASE: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(PhraseQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class)) .or(instanceOf(PointRangeQuery.class)).or(instanceOf(IndexOrDocValuesQuery.class))); break; case PHRASE_PREFIX: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(MultiPhrasePrefixQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class)) .or(instanceOf(PointRangeQuery.class)).or(instanceOf(IndexOrDocValuesQuery.class))); break; } QueryShardContext context = searchContext.getQueryShardContext(); MappedFieldType fieldType = context.fieldMapper(queryBuilder.fieldName()); if (query instanceof TermQuery && fieldType != null) { String queryValue = queryBuilder.value().toString(); if (queryBuilder.analyzer() == null || queryBuilder.analyzer().equals("simple")) { queryValue = queryValue.toLowerCase(Locale.ROOT); } Query expectedTermQuery = fieldType.termQuery(queryValue, context); assertEquals(expectedTermQuery, query); } if (query instanceof BooleanQuery) { BooleanQuery bq = (BooleanQuery) query; if (queryBuilder.minimumShouldMatch() != null) { // calculate expected minimumShouldMatch value int optionalClauses = 0; for (BooleanClause c : bq.clauses()) { if (c.getOccur() == BooleanClause.Occur.SHOULD) { optionalClauses++; } } int msm = Queries.calculateMinShouldMatch(optionalClauses, queryBuilder.minimumShouldMatch()); assertThat(bq.getMinimumNumberShouldMatch(), equalTo(msm)); } if (queryBuilder.analyzer() == null && queryBuilder.value().toString().length() > 0) { assertEquals(bq.clauses().size(), queryBuilder.value().toString().split(" ").length); } } if (query instanceof ExtendedCommonTermsQuery) { assertTrue(queryBuilder.cutoffFrequency() != null); ExtendedCommonTermsQuery ectq = (ExtendedCommonTermsQuery) query; assertEquals(queryBuilder.cutoffFrequency(), ectq.getMaxTermFrequency(), Float.MIN_VALUE); } if (query instanceof FuzzyQuery) { assertTrue(queryBuilder.fuzziness() != null); FuzzyQuery fuzzyQuery = (FuzzyQuery) query; // depending on analyzer being set or not we can have term lowercased along the way, so to simplify test we just // compare lowercased terms here String originalTermLc = queryBuilder.value().toString().toLowerCase(Locale.ROOT); String actualTermLc = fuzzyQuery.getTerm().text().toLowerCase(Locale.ROOT); Matcher<String> termLcMatcher = equalTo(originalTermLc); if ("false".equals(originalTermLc) || "true".equals(originalTermLc)) { // Booleans become t/f when querying a boolean field termLcMatcher = either(termLcMatcher).or(equalTo(originalTermLc.substring(0, 1))); } assertThat(actualTermLc, termLcMatcher); assertThat(queryBuilder.prefixLength(), equalTo(fuzzyQuery.getPrefixLength())); assertThat(queryBuilder.fuzzyTranspositions(), equalTo(fuzzyQuery.getTranspositions())); } if (query instanceof PointRangeQuery) { // TODO } }
@Override protected void doAssertLuceneQuery(MatchQueryBuilder queryBuilder, Query query, SearchContext searchContext) throws IOException { assertThat(query, notNullValue()); if (query instanceof MatchAllDocsQuery) { assertThat(queryBuilder.zeroTermsQuery(), equalTo(ZeroTermsQuery.ALL)); return; } switch (queryBuilder.type()) { case BOOLEAN: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(ExtendedCommonTermsQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class)).or(instanceOf(MatchNoDocsQuery.class)) .or(instanceOf(PointRangeQuery.class))); break; case PHRASE: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(PhraseQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class)) .or(instanceOf(PointRangeQuery.class))); break; case PHRASE_PREFIX: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(MultiPhrasePrefixQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class)) .or(instanceOf(PointRangeQuery.class))); break; } QueryShardContext context = searchContext.getQueryShardContext(); MappedFieldType fieldType = context.fieldMapper(queryBuilder.fieldName()); if (query instanceof TermQuery && fieldType != null) { String queryValue = queryBuilder.value().toString(); if (queryBuilder.analyzer() == null || queryBuilder.analyzer().equals("simple")) { queryValue = queryValue.toLowerCase(Locale.ROOT); } Query expectedTermQuery = fieldType.termQuery(queryValue, context); assertEquals(expectedTermQuery, query); } if (query instanceof BooleanQuery) { BooleanQuery bq = (BooleanQuery) query; if (queryBuilder.minimumShouldMatch() != null) { // calculate expected minimumShouldMatch value int optionalClauses = 0; for (BooleanClause c : bq.clauses()) { if (c.getOccur() == BooleanClause.Occur.SHOULD) { optionalClauses++; } } int msm = Queries.calculateMinShouldMatch(optionalClauses, queryBuilder.minimumShouldMatch()); assertThat(bq.getMinimumNumberShouldMatch(), equalTo(msm)); } if (queryBuilder.analyzer() == null && queryBuilder.value().toString().length() > 0) { assertEquals(bq.clauses().size(), queryBuilder.value().toString().split(" ").length); } } if (query instanceof ExtendedCommonTermsQuery) { assertTrue(queryBuilder.cutoffFrequency() != null); ExtendedCommonTermsQuery ectq = (ExtendedCommonTermsQuery) query; assertEquals(queryBuilder.cutoffFrequency(), ectq.getMaxTermFrequency(), Float.MIN_VALUE); } if (query instanceof FuzzyQuery) { assertTrue(queryBuilder.fuzziness() != null); FuzzyQuery fuzzyQuery = (FuzzyQuery) query; // depending on analyzer being set or not we can have term lowercased along the way, so to simplify test we just // compare lowercased terms here String originalTermLc = queryBuilder.value().toString().toLowerCase(Locale.ROOT); String actualTermLc = fuzzyQuery.getTerm().text().toLowerCase(Locale.ROOT); Matcher<String> termLcMatcher = equalTo(originalTermLc); if ("false".equals(originalTermLc) || "true".equals(originalTermLc)) { // Booleans become t/f when querying a boolean field termLcMatcher = either(termLcMatcher).or(equalTo(originalTermLc.substring(0, 1))); } assertThat(actualTermLc, termLcMatcher); assertThat(queryBuilder.prefixLength(), equalTo(fuzzyQuery.getPrefixLength())); assertThat(queryBuilder.fuzzyTranspositions(), equalTo(fuzzyQuery.getTranspositions())); } if (query instanceof PointRangeQuery) { // TODO } }
@Override protected void doAssertLuceneQuery(MatchQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException { assertThat(query, notNullValue()); if (query instanceof MatchAllDocsQuery) { assertThat(queryBuilder.zeroTermsQuery(), equalTo(ZeroTermsQuery.ALL)); return; } switch (queryBuilder.type()) { case BOOLEAN: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(ExtendedCommonTermsQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class)).or(instanceOf(MatchNoDocsQuery.class)) .or(instanceOf(PointRangeQuery.class))); break; case PHRASE: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(PhraseQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class)) .or(instanceOf(PointRangeQuery.class))); break; case PHRASE_PREFIX: assertThat(query, either(instanceOf(BooleanQuery.class)).or(instanceOf(MultiPhrasePrefixQuery.class)) .or(instanceOf(TermQuery.class)).or(instanceOf(FuzzyQuery.class)) .or(instanceOf(PointRangeQuery.class))); break; } MappedFieldType fieldType = context.fieldMapper(queryBuilder.fieldName()); if (query instanceof TermQuery && fieldType != null) { String queryValue = queryBuilder.value().toString(); if (queryBuilder.analyzer() == null || queryBuilder.analyzer().equals("simple")) { queryValue = queryValue.toLowerCase(Locale.ROOT); } Query expectedTermQuery = fieldType.termQuery(queryValue, context); assertEquals(expectedTermQuery, query); } if (query instanceof BooleanQuery) { BooleanQuery bq = (BooleanQuery) query; if (queryBuilder.minimumShouldMatch() != null) { // calculate expected minimumShouldMatch value int optionalClauses = 0; for (BooleanClause c : bq.clauses()) { if (c.getOccur() == BooleanClause.Occur.SHOULD) { optionalClauses++; } } int msm = Queries.calculateMinShouldMatch(optionalClauses, queryBuilder.minimumShouldMatch()); assertThat(bq.getMinimumNumberShouldMatch(), equalTo(msm)); } if (queryBuilder.analyzer() == null && queryBuilder.value().toString().length() > 0) { assertEquals(bq.clauses().size(), queryBuilder.value().toString().split(" ").length); } } if (query instanceof ExtendedCommonTermsQuery) { assertTrue(queryBuilder.cutoffFrequency() != null); ExtendedCommonTermsQuery ectq = (ExtendedCommonTermsQuery) query; assertEquals(queryBuilder.cutoffFrequency(), ectq.getMaxTermFrequency(), Float.MIN_VALUE); } if (query instanceof FuzzyQuery) { assertTrue(queryBuilder.fuzziness() != null); FuzzyQuery fuzzyQuery = (FuzzyQuery) query; // depending on analyzer being set or not we can have term lowercased along the way, so to simplify test we just // compare lowercased terms here String originalTermLc = queryBuilder.value().toString().toLowerCase(Locale.ROOT); String actualTermLc = fuzzyQuery.getTerm().text().toLowerCase(Locale.ROOT); Matcher<String> termLcMatcher = equalTo(originalTermLc); if ("false".equals(originalTermLc) || "true".equals(originalTermLc)) { // Booleans become t/f when querying a boolean field termLcMatcher = either(termLcMatcher).or(equalTo(originalTermLc.substring(0, 1))); } assertThat(actualTermLc, termLcMatcher); assertThat(queryBuilder.prefixLength(), equalTo(fuzzyQuery.getPrefixLength())); assertThat(queryBuilder.fuzzyTranspositions(), equalTo(fuzzyQuery.getTranspositions())); } if (query instanceof PointRangeQuery) { // TODO } }
Usage snippet has been bookmarked! Review your bookmarks
Thank you! Review your likes