本文整理了Java中org.apache.lucene.search.Query
类的一些代码示例,展示了Query
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query
类的具体详情如下:
包路径:org.apache.lucene.search.Query
类名称:Query
[英]The abstract base class for queries.
Instantiable subclasses are:
See also the family of org.apache.lucene.search.spansand additional queries available in the Queries module
[中]查询的抽象基类。
可实例化的子类包括:
*术语查询
*布尔查询
*通配符查询
*短语查询
*前缀查询
*多重措辞
*模糊查询
*RegexpQuery
*TermRangeQuery
*数字范围查询
*康斯坦索查询
*析取MaxQuery
*相配的
另见org家族。阿帕奇。卢森。搜索span和Queries module中提供的其他查询
代码示例来源:origin: oracle/opengrok
/**
* Gets the instance from {@code search(...)} if it was called.
* @return defined instance or {@code null}
*/
public String getQuery() {
return query != null ? query.toString() : null;
}
代码示例来源:origin: org.apache.lucene/lucene-core
/** Expert: called to re-write queries into primitive queries.
* @throws BooleanQuery.TooManyClauses If a query would exceed
* {@link BooleanQuery#getMaxClauseCount()} clauses.
*/
public Query rewrite(Query original) throws IOException {
Query query = original;
for (Query rewrittenQuery = query.rewrite(reader); rewrittenQuery != query;
rewrittenQuery = query.rewrite(reader)) {
query = rewrittenQuery;
}
return query;
}
代码示例来源:origin: org.apache.lucene/lucene-core
@Override
public DoubleValuesSource rewrite(IndexSearcher searcher) throws IOException {
return new WeightDoubleValuesSource(searcher.rewrite(query).createWeight(searcher, true, 1f));
}
代码示例来源:origin: org.infinispan/infinispan-query
@Test
public void testBeAbleToProjectUnqualifiedField() {
LuceneQueryParsingResult<Class<?>> result = parseAndTransform("SELECT name, text FROM org.infinispan.query.dsl.embedded.impl.model.Employee e JOIN e.contactDetails d");
assertThat(result.getQuery().toString()).isEqualTo("*:*");
assertThat(result.getProjections()).containsOnly("name", "text");
}
代码示例来源:origin: org.infinispan/infinispan-query
@Test
public void testProjectionQuery() {
LuceneQueryParsingResult<Class<?>> parsingResult = parseAndTransform("select e.id, e.name from org.infinispan.query.dsl.embedded.impl.model.Employee e");
assertThat(parsingResult.getQuery().toString()).isEqualTo("*:*");
assertThat(parsingResult.getProjections()).isEqualTo(new String[]{"id", "name"});
}
代码示例来源:origin: rnewson/couchdb-lucene
queryRow.put("q", q.toString());
if (getBooleanParameter(req, "debug")) {
queryRow.put("plan", QueryPlan.toPlan(q));
final Query rewritten_q = q.rewrite(searcher
.getIndexReader());
queryRow.put("rewritten_q", rewritten_q.toString());
final Weight weight = rewritten_q.createWeight(searcher, false);
weight.extractTerms(terms);
for (final Object term : terms) {
final int freq = searcher.getIndexReader().docFreq((Term) term);
freqs.put(term.toString(), freq);
td = searcher.search(q, skip + limit);
} else {
td = searcher.search(q, skip + limit, sort);
代码示例来源:origin: hibernate/hibernate-search
private Set<Term> extractTerms(Query query, Class<?> indexedType) throws IOException {
IndexReader reader = null;
try {
Set<Term> terms = new HashSet<Term>( 100 );
reader = sfHolder.getSearchFactory().getIndexReaderAccessor().open( indexedType );
query.createWeight( new IndexSearcher( reader ), false ).extractTerms( terms );
return terms;
}
finally {
if ( reader != null ) {
reader.close();
}
}
}
代码示例来源:origin: hibernate/hibernate-search
@Override
public void close() {
final IndexReader indexReader = searcher.getIndexReader();
try {
MultiReaderFactory.closeReader( indexReader );
}
catch (SearchException e) {
log.unableToCloseSearcherDuringQuery( userQuery.toString(), e );
}
}
代码示例来源:origin: larsga/Duke
termQuery.setBoost(boost);
parent.add(termQuery, required ? Occur.MUST : Occur.SHOULD);
代码示例来源:origin: hibernate/hibernate-search
private Query rewrittenQuery() throws IOException {
if ( rewrittenQuery == null ) {
//Apply faceting filters:
final Query effectiveQuery = facetingFilters.filterOrPassthrough( userQuery );
rewrittenQuery = effectiveQuery.rewrite( searcher.getIndexReader() );
}
return rewrittenQuery;
}
}
代码示例来源:origin: org.apache.lucene/lucene-core
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
final int minShouldMatch = query.getMinimumNumberShouldMatch();
List<Explanation> subs = new ArrayList<>();
float sum = 0.0f;
int matchCount = 0;
int shouldMatchCount = 0;
Iterator<BooleanClause> cIter = query.iterator();
for (Iterator<Weight> wIter = weights.iterator(); wIter.hasNext();) {
Weight w = wIter.next();
BooleanClause c = cIter.next();
Explanation e = w.explain(context, doc);
if (e.isMatch()) {
if (c.isScoring()) {
Explanation.match(0f, Occur.FILTER + " clause"), e));
} else if (c.isProhibited()) {
subs.add(Explanation.noMatch("match on prohibited clause (" + c.getQuery().toString() + ")", e));
fail = true;
subs.add(Explanation.noMatch("no match on required clause (" + c.getQuery().toString() + ")", e));
fail = true;
代码示例来源:origin: org.elasticsearch/elasticsearch
final Weight nestedWeight = filter.createWeight(sc.searcher(), false, 1f);
Scorer scorer = nestedWeight.scorer(context);
if (scorer == null) {
continue;
代码示例来源:origin: org.apache.lucene/lucene-core
public String toString(String field) {
StringBuilder buffer = new StringBuilder();
boolean needParens = getMinimumNumberShouldMatch() > 0;
if (needParens) {
buffer.append("(");
if (subQuery instanceof BooleanQuery) { // wrap sub-bools in parens
buffer.append("(");
buffer.append(subQuery.toString(field));
buffer.append(")");
} else {
buffer.append(subQuery.toString(field));
if (getMinimumNumberShouldMatch()>0) {
buffer.append('~');
buffer.append(getMinimumNumberShouldMatch());
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
Explanation expl = subQueryWeight.explain(context, doc);
if (!expl.isMatch()) {
return expl;
if (filterWeights[i] != null) {
final Bits docSet = Lucene.asSequentialAccessBits(
context.reader().maxDoc(), filterWeights[i].scorerSupplier(context));
if (docSet.get(doc) == false) {
continue;
Query filterQuery = ((FilterScoreFunction) function).filter;
Explanation filterExplanation = Explanation.match(sc, "function score, product of:",
Explanation.match(1.0f, "match filter: " + filterQuery.toString()), functionExplanation);
functionsExplanations.add(filterExplanation);
} else {
代码示例来源:origin: org.apache.lucene/lucene-core
final int threshold = Math.min(BOOLEAN_REWRITE_TERM_COUNT_THRESHOLD, BooleanQuery.getMaxClauseCount());
assert termData.size() > threshold : "Query should have been rewritten";
List<TermAndState> matchingTerms = new ArrayList<>(threshold);
BooleanQuery.Builder bq = new BooleanQuery.Builder();
for (TermAndState t : matchingTerms) {
final TermContext termContext = new TermContext(searcher.getTopReaderContext());
termContext.register(t.state, context.ord, t.docFreq, t.totalTermFreq);
bq.add(new TermQuery(new Term(t.field, t.term), termContext), Occur.SHOULD);
final Weight weight = searcher.rewrite(q).createWeight(searcher, needsScores, score());
return new WeightOrDocIdSet(weight);
} else {
代码示例来源:origin: harbby/presto-connectors
private String getRewrittenQuery(IndexSearcher searcher, Query query) throws IOException {
Query queryRewrite = searcher.rewrite(query);
if (queryRewrite instanceof MatchNoDocsQuery) {
return query.toString();
} else {
return queryRewrite.toString();
}
}
}
代码示例来源:origin: org.apache.lucene/com.springsource.org.apache.lucene
protected Weight createWeight(Searcher searcher) throws IOException {
if (terms.size() == 1) { // optimize one-term case
Term term = (Term)terms.get(0);
Query termQuery = new TermQuery(term);
termQuery.setBoost(getBoost());
return termQuery.createWeight(searcher);
}
return new PhraseWeight(searcher);
}
代码示例来源:origin: org.apache.lucene/lucene-core
@Override
public Query rewrite(IndexReader reader) throws IOException {
final int threshold = Math.min(BOOLEAN_REWRITE_TERM_COUNT_THRESHOLD, BooleanQuery.getMaxClauseCount());
if (termData.size() <= threshold) {
BooleanQuery.Builder bq = new BooleanQuery.Builder();
TermIterator iterator = termData.iterator();
for (BytesRef term = iterator.next(); term != null; term = iterator.next()) {
bq.add(new TermQuery(new Term(iterator.field(), BytesRef.deepCopyOf(term))), Occur.SHOULD);
}
return new ConstantScoreQuery(bq.build());
}
return super.rewrite(reader);
}
代码示例来源:origin: org.apache.lucene/com.springsource.org.apache.lucene
/** Expert: Constructs and initializes a Weight for a top-level query. */
public Weight weight(Searcher searcher)
throws IOException {
Query query = searcher.rewrite(this);
Weight weight = query.createWeight(searcher);
float sum = weight.sumOfSquaredWeights();
float norm = getSimilarity(searcher).queryNorm(sum);
weight.normalize(norm);
return weight;
}
代码示例来源:origin: org.infinispan/infinispan-embedded-query
@Override
public Query rewrite(IndexReader r) throws IOException {
if (getBoost() != 1f) {
return super.rewrite(r);
}
BooleanQuery rewritten = getBooleanQuery();
if (rewritten.clauses().isEmpty()) {
return new MatchAllDocsQuery();
}
return rewritten;
}
内容来源于网络,如有侵权,请联系作者删除!