本文整理汇总了Java中org.apache.lucene.queries.BlendedTermQuery.booleanBlendedQuery方法的典型用法代码示例。如果您正苦于以下问题:Java BlendedTermQuery.booleanBlendedQuery方法的具体用法?Java BlendedTermQuery.booleanBlendedQuery怎么用?Java BlendedTermQuery.booleanBlendedQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.queries.BlendedTermQuery
的用法示例。
在下文中一共展示了BlendedTermQuery.booleanBlendedQuery方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBlendTermsUnsupportedValue
import org.apache.lucene.queries.BlendedTermQuery; //导入方法依赖的package包/类
public void testBlendTermsUnsupportedValue() {
FakeFieldType ft1 = new FakeFieldType();
ft1.setName("foo");
FakeFieldType ft2 = new FakeFieldType() {
@Override
public Query termQuery(Object value, QueryShardContext context) {
throw new IllegalArgumentException();
}
};
ft2.setName("bar");
Term[] terms = new Term[] { new Term("foo", "baz") };
float[] boosts = new float[] {2};
Query expected = BlendedTermQuery.booleanBlendedQuery(terms, boosts, false);
Query actual = MultiMatchQuery.blendTerm(
indexService.newQueryShardContext(randomInt(20), null, () -> { throw new UnsupportedOperationException(); }),
new BytesRef("baz"), null, 1f, new FieldAndFieldType(ft1, 2), new FieldAndFieldType(ft2, 3));
assertEquals(expected, actual);
}
示例2: testBlendNoTermQuery
import org.apache.lucene.queries.BlendedTermQuery; //导入方法依赖的package包/类
public void testBlendNoTermQuery() {
FakeFieldType ft1 = new FakeFieldType();
ft1.setName("foo");
FakeFieldType ft2 = new FakeFieldType() {
@Override
public Query termQuery(Object value, QueryShardContext context) {
return new MatchAllDocsQuery();
}
};
ft2.setName("bar");
Term[] terms = new Term[] { new Term("foo", "baz") };
float[] boosts = new float[] {2};
Query expectedClause1 = BlendedTermQuery.booleanBlendedQuery(terms, boosts, false);
Query expectedClause2 = new BoostQuery(new MatchAllDocsQuery(), 3);
Query expected = new BooleanQuery.Builder().setDisableCoord(true)
.add(expectedClause1, Occur.SHOULD)
.add(expectedClause2, Occur.SHOULD)
.build();
Query actual = MultiMatchQuery.blendTerm(
indexService.newQueryShardContext(randomInt(20), null, () -> { throw new UnsupportedOperationException(); }),
new BytesRef("baz"), null, 1f, new FieldAndFieldType(ft1, 2), new FieldAndFieldType(ft2, 3));
assertEquals(expected, actual);
}
示例3: blendTerm
import org.apache.lucene.queries.BlendedTermQuery; //导入方法依赖的package包/类
public Query blendTerm(Term term, MappedFieldType fieldType) {
if (blendedFields == null) {
return super.blendTerm(term, fieldType);
}
final Term[] terms = new Term[blendedFields.length];
float[] blendedBoost = new float[blendedFields.length];
for (int i = 0; i < blendedFields.length; i++) {
terms[i] = blendedFields[i].newTerm(term.text());
blendedBoost[i] = blendedFields[i].boost;
}
if (options.commonTermsCutoff() != null) {
return BlendedTermQuery.commonTermsBlendedQuery(
terms, blendedBoost, false, options.commonTermsCutoff());
}
if (tieBreaker == 1.0f) {
return BlendedTermQuery.booleanBlendedQuery(terms, blendedBoost, false);
}
return BlendedTermQuery.dismaxBlendedQuery(terms, blendedBoost, tieBreaker);
}
示例4: blendTerm
import org.apache.lucene.queries.BlendedTermQuery; //导入方法依赖的package包/类
@Override
public Query blendTerm(Term term, MappedFieldType fieldType) {
if (blendedFields == null) {
return super.blendTerm(term, fieldType);
}
final Term[] terms = new Term[blendedFields.length];
float[] blendedBoost = new float[blendedFields.length];
for (int i = 0; i < blendedFields.length; i++) {
terms[i] = blendedFields[i].newTerm(term.text());
blendedBoost[i] = blendedFields[i].boost;
}
if (commonTermsCutoff != null) {
return BlendedTermQuery.commonTermsBlendedQuery(terms, blendedBoost, false, commonTermsCutoff);
}
if (tieBreaker == 1.0f) {
return BlendedTermQuery.booleanBlendedQuery(terms, blendedBoost, false);
}
return BlendedTermQuery.dismaxBlendedQuery(terms, blendedBoost, tieBreaker);
}
示例5: testExtractQueryMetadata_blendedTermQuery
import org.apache.lucene.queries.BlendedTermQuery; //导入方法依赖的package包/类
public void testExtractQueryMetadata_blendedTermQuery() {
Term[] termsArr = new Term[]{new Term("_field", "_term1"), new Term("_field", "_term2")};
BlendedTermQuery commonTermsQuery = BlendedTermQuery.booleanBlendedQuery(termsArr, false);
Result result = analyze(commonTermsQuery);
assertThat(result.verified, is(true));
List<Term> terms = new ArrayList<>(result.terms);
Collections.sort(terms);
assertThat(terms.size(), equalTo(2));
assertThat(terms.get(0).field(), equalTo("_field"));
assertThat(terms.get(0).text(), equalTo("_term1"));
assertThat(terms.get(1).field(), equalTo("_field"));
assertThat(terms.get(1).text(), equalTo("_term2"));
}
示例6: testBlendTerms
import org.apache.lucene.queries.BlendedTermQuery; //导入方法依赖的package包/类
public void testBlendTerms() {
FakeFieldType ft1 = new FakeFieldType();
ft1.setName("foo");
FakeFieldType ft2 = new FakeFieldType();
ft2.setName("bar");
Term[] terms = new Term[] { new Term("foo", "baz"), new Term("bar", "baz") };
float[] boosts = new float[] {2, 3};
Query expected = BlendedTermQuery.booleanBlendedQuery(terms, boosts, false);
Query actual = MultiMatchQuery.blendTerm(
indexService.newQueryShardContext(randomInt(20), null, () -> { throw new UnsupportedOperationException(); }),
new BytesRef("baz"), null, 1f, new FieldAndFieldType(ft1, 2), new FieldAndFieldType(ft2, 3));
assertEquals(expected, actual);
}
示例7: testBlendTermsWithFieldBoosts
import org.apache.lucene.queries.BlendedTermQuery; //导入方法依赖的package包/类
public void testBlendTermsWithFieldBoosts() {
FakeFieldType ft1 = new FakeFieldType();
ft1.setName("foo");
ft1.setBoost(100);
FakeFieldType ft2 = new FakeFieldType();
ft2.setName("bar");
ft2.setBoost(10);
Term[] terms = new Term[] { new Term("foo", "baz"), new Term("bar", "baz") };
float[] boosts = new float[] {200, 30};
Query expected = BlendedTermQuery.booleanBlendedQuery(terms, boosts, false);
Query actual = MultiMatchQuery.blendTerm(
indexService.newQueryShardContext(randomInt(20), null, () -> { throw new UnsupportedOperationException(); }),
new BytesRef("baz"), null, 1f, new FieldAndFieldType(ft1, 2), new FieldAndFieldType(ft2, 3));
assertEquals(expected, actual);
}
示例8: testNoMatchQueries
import org.apache.lucene.queries.BlendedTermQuery; //导入方法依赖的package包/类
public void testNoMatchQueries() throws IOException {
String userQuery = "brown cow";
Term[] termsToBlend = new Term[]{new Term("field", userQuery.split(" ")[0])};
Query blended = BlendedTermQuery.booleanBlendedQuery(termsToBlend, false);
List<PrebuiltFeature> features = Arrays.asList(
new PrebuiltFeature(null, new TermQuery(new Term("field", "missingterm"))),
new PrebuiltFeature(null, blended));
checkModelWithFeatures(features, null);
}
示例9: testDuelSpecificQueries
import org.apache.lucene.queries.BlendedTermQuery; //导入方法依赖的package包/类
public void testDuelSpecificQueries() throws Exception {
List<ParseContext.Document> documents = new ArrayList<>();
CommonTermsQuery commonTermsQuery = new CommonTermsQuery(BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD, 128);
commonTermsQuery.add(new Term("field", "quick"));
commonTermsQuery.add(new Term("field", "brown"));
commonTermsQuery.add(new Term("field", "fox"));
addQuery(commonTermsQuery, documents);
BlendedTermQuery blendedTermQuery = BlendedTermQuery.booleanBlendedQuery(new Term[]{new Term("field", "quick"),
new Term("field", "brown"), new Term("field", "fox")}, false);
addQuery(blendedTermQuery, documents);
SpanNearQuery spanNearQuery = new SpanNearQuery.Builder("field", true)
.addClause(new SpanTermQuery(new Term("field", "quick")))
.addClause(new SpanTermQuery(new Term("field", "brown")))
.addClause(new SpanTermQuery(new Term("field", "fox")))
.build();
addQuery(spanNearQuery, documents);
SpanNearQuery spanNearQuery2 = new SpanNearQuery.Builder("field", true)
.addClause(new SpanTermQuery(new Term("field", "the")))
.addClause(new SpanTermQuery(new Term("field", "lazy")))
.addClause(new SpanTermQuery(new Term("field", "doc")))
.build();
SpanOrQuery spanOrQuery = new SpanOrQuery(
spanNearQuery,
spanNearQuery2
);
addQuery(spanOrQuery, documents);
SpanNotQuery spanNotQuery = new SpanNotQuery(spanNearQuery, spanNearQuery);
addQuery(spanNotQuery, documents);
long lowerLong = randomIntBetween(0, 256);
long upperLong = lowerLong + randomIntBetween(0, 32);
addQuery(LongPoint.newRangeQuery("long_field", lowerLong, upperLong), documents);
indexWriter.addDocuments(documents);
indexWriter.close();
directoryReader = DirectoryReader.open(directory);
IndexSearcher shardSearcher = newSearcher(directoryReader);
// Disable query cache, because ControlQuery cannot be cached...
shardSearcher.setQueryCache(null);
Document document = new Document();
document.add(new TextField("field", "the quick brown fox jumps over the lazy dog", Field.Store.NO));
long randomLong = randomIntBetween((int) lowerLong, (int) upperLong);
document.add(new LongPoint("long_field", randomLong));
MemoryIndex memoryIndex = MemoryIndex.fromDocument(document, new WhitespaceAnalyzer());
duelRun(queryStore, memoryIndex, shardSearcher);
}
示例10: testOnRewrittenQueries
import org.apache.lucene.queries.BlendedTermQuery; //导入方法依赖的package包/类
public void testOnRewrittenQueries() throws IOException {
String userQuery = "brown cow";
Term[] termsToBlend = new Term[]{new Term("field", userQuery.split(" ")[0])};
Query blended = BlendedTermQuery.booleanBlendedQuery(termsToBlend, false);
List<Query> features = Arrays.asList(new TermQuery(new Term("field", userQuery.split(" ")[0])), blended);
checkModelWithFeatures(toPrebuildFeatureWithNoName(features), null);
}