本文整理汇总了Java中org.apache.lucene.util.QueryBuilder类的典型用法代码示例。如果您正苦于以下问题:Java QueryBuilder类的具体用法?Java QueryBuilder怎么用?Java QueryBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueryBuilder类属于org.apache.lucene.util包,在下文中一共展示了QueryBuilder类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getQueryBuilder
import org.apache.lucene.util.QueryBuilder; //导入依赖的package包/类
public QueryBuilder getQueryBuilder() {
return queryBuilder;
}
示例2: parseFieldQuery
import org.apache.lucene.util.QueryBuilder; //导入依赖的package包/类
static Query parseFieldQuery(QParser parser, Analyzer analyzer, String field, String queryText) {
// note, this method always worked this way (but nothing calls it?) because it has no idea of quotes...
return new QueryBuilder(analyzer).createPhraseQuery(field, queryText);
}
示例3: parseFieldQuery
import org.apache.lucene.util.QueryBuilder; //导入依赖的package包/类
static Query parseFieldQuery(QParser parser, Analyzer analyzer, String field, String queryText)
{
// note, this method always worked this way (but nothing calls it?) because it has no idea of quotes...
return new QueryBuilder(analyzer).createPhraseQuery(field, queryText);
}
示例4: getPhraseFieldQueries
import org.apache.lucene.util.QueryBuilder; //导入依赖的package包/类
protected Optional<Query> getPhraseFieldQueries() {
// sloppy phrase queries for proximity
final List<FieldParams> allPhraseFields = bmaxquery.getAllPhraseFields();
if (!allPhraseFields.isEmpty()) {
final List<BmaxTerm> bmaxTerms = bmaxquery.getTerms();
if (bmaxTerms.size() > 1) { // it's a phrase
final List<CharSequence> terms = bmaxTerms.stream().map(BmaxTerm::getTerm).collect(Collectors.toList());
final List<Query> disjuncts = new LinkedList<>();
final QueryBuilder queryBuilder = new QueryBuilder(schema.getQueryAnalyzer());
// memoization of phrase shingles
final Map<Integer, List<String>> shingles = new HashMap<>(2);
// build phrase queries for the phrase query fields
for (final FieldParams fieldParams : allPhraseFields) {
final int phraseLength = fieldParams.getWordGrams();
final int slop = fieldParams.getSlop();
final String fieldname = fieldParams.getField();
// get/create field-independent bi-gram or tri-gram strings
final List<String> shinglesN = shingles.computeIfAbsent(phraseLength, n -> buildNGrams(terms, n));
// map bi-gram/tri-gram strings to phrase queries
final List<Query> nGramQueries = shinglesN.stream()
.map(nGram -> queryBuilder.createPhraseQuery(fieldname, nGram, slop))
.filter(Objects::nonNull)
.collect(Collectors.toList());
switch (nGramQueries.size()) {
case 0: break;
case 1: {
disjuncts.add(withBoostFactor(nGramQueries.get(0), fieldParams.getBoost()));
break;
}
default:
// If we have > 1 n-gram phrase for this field, aggregate their scores using
// a BooleanQuery with all clauses being optional
final BooleanQuery.Builder builder = new BooleanQuery.Builder()
.setMinimumNumberShouldMatch(1);
for (final Query nGramQuery : nGramQueries) {
builder.add(nGramQuery, BooleanClause.Occur.SHOULD);
}
disjuncts.add(withBoostFactor(builder.build(), fieldParams.getBoost()));
}
}
switch (disjuncts.size()) {
case 0: break;
case 1: return Optional.of(disjuncts.get(0));
default :
return Optional.of(new DisjunctionMaxQuery(disjuncts, bmaxquery.getPhraseBoostTieBreaker()));
}
}
}
return empty();
}