本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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"));
}
示例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"));
}
示例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"));
}
示例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));
}
示例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"));
}
示例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"));
}