当前位置: 首页>>代码示例>>Java>>正文


Java DisjunctionMaxQuery类代码示例

本文整理汇总了Java中org.apache.lucene.search.DisjunctionMaxQuery的典型用法代码示例。如果您正苦于以下问题:Java DisjunctionMaxQuery类的具体用法?Java DisjunctionMaxQuery怎么用?Java DisjunctionMaxQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DisjunctionMaxQuery类属于org.apache.lucene.search包,在下文中一共展示了DisjunctionMaxQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testToQueryPhraseQuery

import org.apache.lucene.search.DisjunctionMaxQuery; //导入依赖的package包/类
public void testToQueryPhraseQuery() throws IOException {
    assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
    Query query = queryStringQuery("\"term1 term2\"")
        .defaultField(STRING_FIELD_NAME)
        .phraseSlop(3)
        .toQuery(createShardContext());
    assertThat(query, instanceOf(DisjunctionMaxQuery.class));
    DisjunctionMaxQuery disjunctionMaxQuery = (DisjunctionMaxQuery) query;
    assertThat(disjunctionMaxQuery.getDisjuncts().size(), equalTo(1));
    assertThat(disjunctionMaxQuery.getDisjuncts().get(0), instanceOf(PhraseQuery.class));
    PhraseQuery phraseQuery = (PhraseQuery)disjunctionMaxQuery.getDisjuncts().get(0);
    assertThat(phraseQuery.getTerms().length, equalTo(2));
    assertThat(phraseQuery.getTerms()[0], equalTo(new Term(STRING_FIELD_NAME, "term1")));
    assertThat(phraseQuery.getTerms()[1], equalTo(new Term(STRING_FIELD_NAME, "term2")));
    assertThat(phraseQuery.getSlop(), equalTo(3));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:QueryStringQueryBuilderTests.java

示例2: testToQueryPhraseQueryBoostAndSlop

import org.apache.lucene.search.DisjunctionMaxQuery; //导入依赖的package包/类
public void testToQueryPhraseQueryBoostAndSlop() throws IOException {
    assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
    QueryStringQueryBuilder queryStringQueryBuilder =
        new QueryStringQueryBuilder("\"test phrase\"~2").field(STRING_FIELD_NAME, 5f);
    Query query = queryStringQueryBuilder.toQuery(createShardContext());
    assertThat(query, instanceOf(DisjunctionMaxQuery.class));
    DisjunctionMaxQuery disjunctionMaxQuery = (DisjunctionMaxQuery) query;
    assertThat(disjunctionMaxQuery.getDisjuncts().size(), equalTo(1));
    assertThat(disjunctionMaxQuery.getDisjuncts().get(0), instanceOf(BoostQuery.class));
    BoostQuery boostQuery = (BoostQuery) disjunctionMaxQuery.getDisjuncts().get(0);
    assertThat(boostQuery.getBoost(), equalTo(5f));
    assertThat(boostQuery.getQuery(), instanceOf(PhraseQuery.class));
    PhraseQuery phraseQuery = (PhraseQuery) boostQuery.getQuery();
    assertThat(phraseQuery.getSlop(), Matchers.equalTo(2));
    assertThat(phraseQuery.getTerms().length, equalTo(2));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:QueryStringQueryBuilderTests.java

示例3: testCrossFieldMultiMatchQuery

import org.apache.lucene.search.DisjunctionMaxQuery; //导入依赖的package包/类
public void testCrossFieldMultiMatchQuery() throws IOException {
    QueryShardContext queryShardContext = indexService.newQueryShardContext(
            randomInt(20), null, () -> { throw new UnsupportedOperationException(); });
    queryShardContext.setAllowUnmappedFields(true);
    Query parsedQuery = multiMatchQuery("banon").field("name.first", 2).field("name.last", 3).field("foobar").type(MultiMatchQueryBuilder.Type.CROSS_FIELDS).toQuery(queryShardContext);
    try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        Query rewrittenQuery = searcher.searcher().rewrite(parsedQuery);

        BooleanQuery.Builder expected = new BooleanQuery.Builder();
        expected.add(new TermQuery(new Term("foobar", "banon")), BooleanClause.Occur.SHOULD);
        Query tq1 = new BoostQuery(new TermQuery(new Term("name.first", "banon")), 2);
        Query tq2 = new BoostQuery(new TermQuery(new Term("name.last", "banon")), 3);
        expected.add(new DisjunctionMaxQuery(Arrays.<Query>asList(tq1, tq2), 0f), BooleanClause.Occur.SHOULD);
        assertEquals(expected.build(), rewrittenQuery);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:MultiMatchQueryTests.java

示例4: getQuery

import org.apache.lucene.search.DisjunctionMaxQuery; //导入依赖的package包/类
@Override
public Query getQuery(Element e) throws ParserException {
  float tieBreaker = DOMUtils.getAttribute(e, "tieBreaker", 0.0f); 
  DisjunctionMaxQuery dq = new DisjunctionMaxQuery(tieBreaker);
  dq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));

  NodeList nl = e.getChildNodes();
  for (int i = 0; i < nl.getLength(); i++) {
    Node node = nl.item(i);
    if (node instanceof Element) { // all elements are disjuncts.
      Element queryElem = (Element) node;
      Query q = factory.getQuery(queryElem);
      dq.add(q);
    }
  }

  return dq;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:DisjunctionMaxQueryBuilder.java

示例5: combineGrouped

import org.apache.lucene.search.DisjunctionMaxQuery; //导入依赖的package包/类
public Query combineGrouped(List<Query> queries) {
    if (queries == null || queries.isEmpty()) {
        return null;
    }
    if (queries.size() == 1) {
        return queries.get(0);
    }
    if (groupDismax) {
        return new DisjunctionMaxQuery(queries, tieBreaker);
    } else {
        BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
        for (Query query : queries) {
            booleanQuery.add(query, BooleanClause.Occur.SHOULD);
        }
        return booleanQuery.build();
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:MultiMatchQueryBuilder.java

示例6: construct

import org.apache.lucene.search.DisjunctionMaxQuery; //导入依赖的package包/类
@Override
protected Query construct(LindenQuery lindenQuery, LindenConfig config) throws Exception {
  if (!lindenQuery.isSetDisMaxQuery()) {
    return null;
  }

  LindenDisMaxQuery disMaxQuery = lindenQuery.getDisMaxQuery();
  DisjunctionMaxQuery disjunctionMaxQuery = new DisjunctionMaxQuery((float) disMaxQuery.getTie());
  for (LindenQuery subLindenQuery : disMaxQuery.getQueries()) {
    Query query = QueryConstructor.constructQuery(subLindenQuery, config);
    if (query != null) {
      disjunctionMaxQuery.add(query);
    }
  }
  return disjunctionMaxQuery;
}
 
开发者ID:XiaoMi,项目名称:linden,代码行数:17,代码来源:DisMaxQueryConstructor.java

示例7: containsClause

import org.apache.lucene.search.DisjunctionMaxQuery; //导入依赖的package包/类
private boolean containsClause(Query query, String field, String value,
    int boost, boolean fuzzy) {
  
  if(query instanceof BooleanQuery) {
    return containsClause((BooleanQuery)query, field, value, boost, fuzzy);
  }
  if(query instanceof DisjunctionMaxQuery) {
    return containsClause((DisjunctionMaxQuery)query, field, value, boost, fuzzy);
  }
  if(query instanceof TermQuery && !fuzzy) {
    return containsClause((TermQuery)query, field, value, boost);
  }
  if(query instanceof FuzzyQuery && fuzzy) {
    return containsClause((FuzzyQuery)query, field, value, boost);
  }
  return false;
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:TestExtendedDismaxParser.java

示例8: testExtractTwoSubqueries

import org.apache.lucene.search.DisjunctionMaxQuery; //导入依赖的package包/类
@Test
public void testExtractTwoSubqueries() {
  Query q1 = mock(Query.class);
  Query q2 = mock(Query.class);

  DisjunctionQueryExtractor disjunctionQueryExtracotr = new DisjunctionQueryExtractor();

  List<Query> disjunctQueries = new ArrayList<>();
  disjunctQueries.add(q1);
  disjunctQueries.add(q2);
  DisjunctionMaxQuery disjunctionMaxQuery = new DisjunctionMaxQuery(disjunctQueries, 0.0f);

  List<Query> extractedQueries = new ArrayList<>();

  disjunctionQueryExtracotr.extract(disjunctionMaxQuery, DEFAULT_EXTRACTORS, extractedQueries);
  assertEquals(2, extractedQueries.size());
  assertEquals(q1, extractedQueries.get(0));
  assertEquals(q2, extractedQueries.get(1));
}
 
开发者ID:sematext,项目名称:solr-redis,代码行数:20,代码来源:TestDisjunctionQueryExtracotr.java

示例9: testExtractSubqueryField

import org.apache.lucene.search.DisjunctionMaxQuery; //导入依赖的package包/类
@Test
public void testExtractSubqueryField() {
  Query q1 = new TermQuery(new Term("field1", "value1"));
  Query q2 = new TermQuery(new Term("field2", "value2"));

  DisjunctionQueryExtractor disjunctionQueryExtracotr = new DisjunctionQueryExtractor();

  List<Query> disjunctQueries = new ArrayList<>();
  disjunctQueries.add(q1);
  disjunctQueries.add(q2);
  DisjunctionMaxQuery disjunctionMaxQuery = new DisjunctionMaxQuery(disjunctQueries, 0.0f);

  Set<String> extractedFieldNames = new HashSet<>();

  disjunctionQueryExtracotr.extractSubQueriesFields(disjunctionMaxQuery, DEFAULT_EXTRACTORS, extractedFieldNames);
  assertEquals(2, extractedFieldNames.size());
  assertTrue(extractedFieldNames.contains("field1"));
  assertTrue(extractedFieldNames.contains("field2"));
}
 
开发者ID:sematext,项目名称:solr-redis,代码行数:20,代码来源:TestDisjunctionQueryExtracotr.java

示例10: matchDisjunctionMaxQuery

import org.apache.lucene.search.DisjunctionMaxQuery; //导入依赖的package包/类
protected boolean matchDisjunctionMaxQuery(DisjunctionMaxQuery dmq) {

            if (tieBreaker != dmq.getTieBreakerMultiplier()) {
                return false;
            }

            List<Query> dmqDisjuncts = dmq.getDisjuncts();
            if (dmqDisjuncts == null || dmqDisjuncts.size() != disjuncts.length) {
                return false;
            }

            for (TypeSafeMatcher<? extends Query> disjunct : disjuncts) {
                boolean found = false;
                for (Query q : dmqDisjuncts) {
                    found = disjunct.matches(q);
                    if (found) {
                        break;
                    }
                }
                if (!found) {
                    return false;
                }

            }
            return true;
        }
 
开发者ID:shopping24,项目名称:solr-bmax-queryparser,代码行数:27,代码来源:AbstractLuceneQueryTest.java

示例11: getMultiFieldQuery

import org.apache.lucene.search.DisjunctionMaxQuery; //导入依赖的package包/类
/** Creates a multifield query */
// TODO: investigate more general approach by default, e.g. DisjunctionMaxQuery?
protected Query getMultiFieldQuery(List<Query> queries) throws ParseException {
	if (queries.isEmpty()) {
		return null; // all clause words were filtered away by the analyzer.
	}

	if (dismax) {
		return new DisjunctionMaxQuery(queries, dismaxTie);
	}
	else {
		//mdavis - don't use super method because of min match
		BooleanQuery.Builder query = new BooleanQuery.Builder();
		for (Query sub : queries) {
			query.add(sub, BooleanClause.Occur.SHOULD);
		}

		return query.build();
	}
}
 
开发者ID:lumongo,项目名称:lumongo,代码行数:21,代码来源:LumongoMultiFieldQueryParser.java

示例12: testExtractQueryMetadata_matchNoDocsQuery

import org.apache.lucene.search.DisjunctionMaxQuery; //导入依赖的package包/类
public void testExtractQueryMetadata_matchNoDocsQuery() {
    Result result = analyze(new MatchNoDocsQuery("sometimes there is no reason at all"));
    assertThat(result.verified, is(true));
    assertEquals(0, result.terms.size());

    BooleanQuery.Builder bq = new BooleanQuery.Builder();
    bq.add(new TermQuery(new Term("field", "value")), BooleanClause.Occur.MUST);
    bq.add(new MatchNoDocsQuery("sometimes there is no reason at all"), BooleanClause.Occur.MUST);
    result = analyze(bq.build());
    assertThat(result.verified, is(false));
    assertEquals(0, result.terms.size());

    bq = new BooleanQuery.Builder();
    bq.add(new TermQuery(new Term("field", "value")), BooleanClause.Occur.SHOULD);
    bq.add(new MatchNoDocsQuery("sometimes there is no reason at all"), BooleanClause.Occur.SHOULD);
    result = analyze(bq.build());
    assertThat(result.verified, is(true));
    assertTermsEqual(result.terms, new Term("field", "value"));

    DisjunctionMaxQuery disjunctionMaxQuery = new DisjunctionMaxQuery(
            Arrays.asList(new TermQuery(new Term("field", "value")), new MatchNoDocsQuery("sometimes there is no reason at all")),
            1f
    );
    result = analyze(disjunctionMaxQuery);
    assertThat(result.verified, is(true));
    assertTermsEqual(result.terms, new Term("field", "value"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:QueryAnalyzerTests.java

示例13: doToQuery

import org.apache.lucene.search.DisjunctionMaxQuery; //导入依赖的package包/类
@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
    // return null if there are no queries at all
    Collection<Query> luceneQueries = toQueries(queries, context);
    if (luceneQueries.isEmpty()) {
        return Queries.newMatchNoDocsQuery("no clauses for dismax query.");
    }

    return new DisjunctionMaxQuery(luceneQueries, tieBreaker);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:DisMaxQueryBuilder.java

示例14: doAssertLuceneQuery

import org.apache.lucene.search.DisjunctionMaxQuery; //导入依赖的package包/类
@Override
protected void doAssertLuceneQuery(QueryStringQueryBuilder queryBuilder,
                                   Query query, SearchContext context) throws IOException {
    if ("".equals(queryBuilder.queryString())) {
        assertThat(query, instanceOf(MatchNoDocsQuery.class));
    } else {
        assertThat(query, either(instanceOf(TermQuery.class)).or(instanceOf(AllTermQuery.class))
                .or(instanceOf(BooleanQuery.class)).or(instanceOf(DisjunctionMaxQuery.class))
                .or(instanceOf(PhraseQuery.class)));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:QueryStringQueryBuilderTests.java

示例15: testToQueryMultipleFieldsDisMaxQuery

import org.apache.lucene.search.DisjunctionMaxQuery; //导入依赖的package包/类
public void testToQueryMultipleFieldsDisMaxQuery() throws Exception {
    assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
    Query query = queryStringQuery("test").field(STRING_FIELD_NAME).field(STRING_FIELD_NAME_2)
        .useDisMax(true)
        .toQuery(createShardContext());
    assertThat(query, instanceOf(DisjunctionMaxQuery.class));
    DisjunctionMaxQuery disMaxQuery = (DisjunctionMaxQuery) query;
    List<Query> disjuncts = disMaxQuery.getDisjuncts();
    assertThat(((TermQuery) disjuncts.get(0)).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "test")));
    assertThat(((TermQuery) disjuncts.get(1)).getTerm(), equalTo(new Term(STRING_FIELD_NAME_2, "test")));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:QueryStringQueryBuilderTests.java


注:本文中的org.apache.lucene.search.DisjunctionMaxQuery类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。