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


Java MultiPhraseQuery.add方法代码示例

本文整理汇总了Java中org.apache.lucene.search.MultiPhraseQuery.add方法的典型用法代码示例。如果您正苦于以下问题:Java MultiPhraseQuery.add方法的具体用法?Java MultiPhraseQuery.add怎么用?Java MultiPhraseQuery.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.search.MultiPhraseQuery的用法示例。


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

示例1: testMultiPhraseQueryParsing

import org.apache.lucene.search.MultiPhraseQuery; //导入方法依赖的package包/类
public void testMultiPhraseQueryParsing() throws Exception {
  TokenAndPos[] INCR_0_QUERY_TOKENS_AND = new TokenAndPos[]{
      new TokenAndPos("a", 0),
      new TokenAndPos("1", 0),
      new TokenAndPos("b", 1),
      new TokenAndPos("1", 1),
      new TokenAndPos("c", 2)
  };

  QueryParser qp = new QueryParser("field", new CannedAnalyzer(INCR_0_QUERY_TOKENS_AND));
  Query q = qp.parse("\"this text is acually ignored\"");
  assertTrue("wrong query type!", q instanceof MultiPhraseQuery);

  MultiPhraseQuery multiPhraseQuery = new MultiPhraseQuery();
  multiPhraseQuery.add(new Term[]{ new Term("field", "a"), new Term("field", "1") }, -1);
  multiPhraseQuery.add(new Term[]{ new Term("field", "b"), new Term("field", "1") }, 0);
  multiPhraseQuery.add(new Term[]{ new Term("field", "c") }, 1);

  assertEquals(multiPhraseQuery, q);
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:TestMultiPhraseQueryParsing.java

示例2: testMultiPhraseQueryParsing

import org.apache.lucene.search.MultiPhraseQuery; //导入方法依赖的package包/类
public void testMultiPhraseQueryParsing() throws Exception {
  TokenAndPos[] INCR_0_QUERY_TOKENS_AND = new TokenAndPos[]{
      new TokenAndPos("a", 0),
      new TokenAndPos("1", 0),
      new TokenAndPos("b", 1),
      new TokenAndPos("1", 1),
      new TokenAndPos("c", 2)
  };

  QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new CannedAnalyzer(INCR_0_QUERY_TOKENS_AND));
  Query q = qp.parse("\"this text is acually ignored\"");
  assertTrue("wrong query type!", q instanceof MultiPhraseQuery);

  MultiPhraseQuery multiPhraseQuery = new MultiPhraseQuery();
  multiPhraseQuery.add(new Term[]{ new Term("field", "a"), new Term("field", "1") }, -1);
  multiPhraseQuery.add(new Term[]{ new Term("field", "b"), new Term("field", "1") }, 0);
  multiPhraseQuery.add(new Term[]{ new Term("field", "c") }, 1);

  assertEquals(multiPhraseQuery, q);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:21,代码来源:TestMultiPhraseQueryParsing.java

示例3: testBasic

import org.apache.lucene.search.MultiPhraseQuery; //导入方法依赖的package包/类
public void testBasic() throws Exception {
  MultiPhraseQuery query = new MultiPhraseQuery();
  query.add(new Term[] {                       // #A
      new Term("field", "quick"),              // #A
      new Term("field", "fast")                // #A
  });
  query.add(new Term("field", "fox"));         // #B
  LOGGER.info(query);

  TopDocs hits = searcher.search(query, 10);
  assertEquals("fast fox match", 1, hits.totalHits);

  query.setSlop(1);
  hits = searcher.search(query, 10);
  assertEquals("both match", 2, hits.totalHits);
}
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:17,代码来源:MultiPhraseQueryTest.java

示例4: addExpandedTerms

import org.apache.lucene.search.MultiPhraseQuery; //导入方法依赖的package包/类
private void addExpandedTerms(IndexReader reader, MultiPhraseQuery query, String lastTerm, int count)
	throws IOException
{
	final Term[] expandedTerms = expand(reader, FreeTextQuery.FIELD_NAME_AUTOCOMPLETE, lastTerm);
	if( expandedTerms.length > 0 )
	{
		query.add(expandedTerms, count);
	}
	else if( !lastTerm.isEmpty() )
	{
		query.add(new Term[]{new Term(FreeTextQuery.FIELD_NAME_AUTOCOMPLETE, lastTerm)}, count);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:14,代码来源:ItemIndex.java

示例5: rewrite

import org.apache.lucene.search.MultiPhraseQuery; //导入方法依赖的package包/类
@Override
public Query rewrite(IndexReader reader) throws IOException {
    if (getBoost() != 1.0F) {
        return super.rewrite(reader);
    }
    if (termArrays.isEmpty()) {
        return new MatchNoDocsQuery();
    }
    MultiPhraseQuery query = new MultiPhraseQuery();
    query.setSlop(slop);
    int sizeMinus1 = termArrays.size() - 1;
    for (int i = 0; i < sizeMinus1; i++) {
        query.add(termArrays.get(i), positions.get(i));
    }
    Term[] suffixTerms = termArrays.get(sizeMinus1);
    int position = positions.get(sizeMinus1);
    ObjectHashSet<Term> terms = new ObjectHashSet<>();
    for (Term term : suffixTerms) {
        getPrefixTerms(terms, term, reader);
        if (terms.size() > maxExpansions) {
            break;
        }
    }
    if (terms.isEmpty()) {
        return Queries.newMatchNoDocsQuery();
    }
    query.add(terms.toArray(Term.class), position);
    query.setBoost(getBoost());
    return query.rewrite(reader);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:31,代码来源:MultiPhrasePrefixQuery.java

示例6: rewrite

import org.apache.lucene.search.MultiPhraseQuery; //导入方法依赖的package包/类
public Query rewrite(IndexReader reader) throws IOException {
    MultiPhraseQuery multi = new MultiPhraseQuery();
    for (int i = 0; i < producers.size(); i++) {
        Term[] terms = producers.get(i).getTerms(reader);
        if (terms.length < 1) {
            return matchNoDocsQuery;
        }
        multi.add(terms, positions.get(i));
    }
    return multi.rewrite(reader);
}
 
开发者ID:meltwater,项目名称:meltwater-elasticsearch-queries,代码行数:12,代码来源:WildcardPhraseQuery.java

示例7: testSynonymsPhrase

import org.apache.lucene.search.MultiPhraseQuery; //导入方法依赖的package包/类
/** forms multiphrase query */
public void testSynonymsPhrase() throws Exception {
  MultiPhraseQuery expected = new MultiPhraseQuery();
  expected.add(new Term("field", "old"));
  expected.add(new Term[] { new Term("field", "dogs"), new Term("field", "dog") });
  QueryParser qp = new QueryParser("field", new MockSynonymAnalyzer());
  assertEquals(expected, qp.parse("\"old dogs\""));
  qp.setDefaultOperator(Operator.AND);
  assertEquals(expected, qp.parse("\"old dogs\""));
  expected.setBoost(2.0f);
  assertEquals(expected, qp.parse("\"old dogs\"^2"));
  expected.setSlop(3);
  assertEquals(expected, qp.parse("\"old dogs\"~3^2"));
}
 
开发者ID:europeana,项目名称:search,代码行数:15,代码来源:TestQueryParser.java

示例8: testCJKSynonymsPhrase

import org.apache.lucene.search.MultiPhraseQuery; //导入方法依赖的package包/类
/** forms multiphrase query */
public void testCJKSynonymsPhrase() throws Exception {
  MultiPhraseQuery expected = new MultiPhraseQuery();
  expected.add(new Term("field", "中"));
  expected.add(new Term[] { new Term("field", "国"), new Term("field", "國")});
  QueryParser qp = new QueryParser("field", new MockCJKSynonymAnalyzer());
  qp.setDefaultOperator(Operator.AND);
  assertEquals(expected, qp.parse("\"中国\""));
  expected.setBoost(2.0f);
  assertEquals(expected, qp.parse("\"中国\"^2"));
  expected.setSlop(3);
  assertEquals(expected, qp.parse("\"中国\"~3^2"));
}
 
开发者ID:europeana,项目名称:search,代码行数:14,代码来源:TestQueryParser.java

示例9: testSynonymsPhrase

import org.apache.lucene.search.MultiPhraseQuery; //导入方法依赖的package包/类
/** forms multiphrase query */
public void testSynonymsPhrase() throws Exception {
  MultiPhraseQuery expected = new MultiPhraseQuery();
  expected.add(new Term("field", "old"));
  expected.add(new Term[] { new Term("field", "dogs"), new Term("field", "dog") });
  QueryBuilder builder = new QueryBuilder(new MockSynonymAnalyzer());
  assertEquals(expected, builder.createPhraseQuery("field", "old dogs"));
}
 
开发者ID:europeana,项目名称:search,代码行数:9,代码来源:TestQueryBuilder.java

示例10: testCJKSynonymsPhrase

import org.apache.lucene.search.MultiPhraseQuery; //导入方法依赖的package包/类
/** forms multiphrase query */
public void testCJKSynonymsPhrase() throws Exception {
  MultiPhraseQuery expected = new MultiPhraseQuery();
  expected.add(new Term("field", "中"));
  expected.add(new Term[] { new Term("field", "国"), new Term("field", "國")});
  QueryBuilder builder = new QueryBuilder(new MockCJKSynonymAnalyzer());
  assertEquals(expected, builder.createPhraseQuery("field", "中国"));
  expected.setSlop(3);
  assertEquals(expected, builder.createPhraseQuery("field", "中国", 3));
}
 
开发者ID:europeana,项目名称:search,代码行数:11,代码来源:TestQueryBuilder.java

示例11: testSynonymsPhrase

import org.apache.lucene.search.MultiPhraseQuery; //导入方法依赖的package包/类
/** forms multiphrase query */
public void testSynonymsPhrase() throws Exception {
  MultiPhraseQuery expected = new MultiPhraseQuery();
  expected.add(new Term("field", "old"));
  expected.add(new Term[] { new Term("field", "dogs"), new Term("field", "dog") });
  QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockSynonymAnalyzer());
  assertEquals(expected, qp.parse("\"old dogs\""));
  qp.setDefaultOperator(Operator.AND);
  assertEquals(expected, qp.parse("\"old dogs\""));
  expected.setBoost(2.0f);
  assertEquals(expected, qp.parse("\"old dogs\"^2"));
  expected.setSlop(3);
  assertEquals(expected, qp.parse("\"old dogs\"~3^2"));
}
 
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:15,代码来源:TestQueryParser.java

示例12: testCJKSynonymsPhrase

import org.apache.lucene.search.MultiPhraseQuery; //导入方法依赖的package包/类
/** forms multiphrase query */
public void testCJKSynonymsPhrase() throws Exception {
  MultiPhraseQuery expected = new MultiPhraseQuery();
  expected.add(new Term("field", "中"));
  expected.add(new Term[] { new Term("field", "国"), new Term("field", "國")});
  QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockCJKSynonymAnalyzer());
  qp.setDefaultOperator(Operator.AND);
  assertEquals(expected, qp.parse("\"中国\""));
  expected.setBoost(2.0f);
  assertEquals(expected, qp.parse("\"中国\"^2"));
  expected.setSlop(3);
  assertEquals(expected, qp.parse("\"中国\"~3^2"));
}
 
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:14,代码来源:TestQueryParser.java


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