本文整理汇总了Java中org.apache.lucene.search.PrefixQuery.setRewriteMethod方法的典型用法代码示例。如果您正苦于以下问题:Java PrefixQuery.setRewriteMethod方法的具体用法?Java PrefixQuery.setRewriteMethod怎么用?Java PrefixQuery.setRewriteMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.PrefixQuery
的用法示例。
在下文中一共展示了PrefixQuery.setRewriteMethod方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prefixQuery
import org.apache.lucene.search.PrefixQuery; //导入方法依赖的package包/类
@Override
public final Query prefixQuery(String value, MultiTermQuery.RewriteMethod method, QueryShardContext context) {
failIfNotIndexed();
PrefixQuery query = new PrefixQuery(new Term(name(), indexedValueForSearch(value)));
if (method != null) {
query.setRewriteMethod(method);
}
return query;
}
示例2: build
import org.apache.lucene.search.PrefixQuery; //导入方法依赖的package包/类
@Override
public PrefixQuery build(QueryNode queryNode) throws QueryNodeException {
PrefixWildcardQueryNode wildcardNode = (PrefixWildcardQueryNode) queryNode;
String text = wildcardNode.getText().subSequence(0, wildcardNode.getText().length() - 1).toString();
PrefixQuery q = new PrefixQuery(new Term(wildcardNode.getFieldAsString(), text));
MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod)queryNode.getTag(MultiTermRewriteMethodProcessor.TAG_ID);
if (method != null) {
q.setRewriteMethod(method);
}
return q;
}
示例3: queryFromString
import org.apache.lucene.search.PrefixQuery; //导入方法依赖的package包/类
private static Query queryFromString(Analyzer analyzer, String searchText, int fuzzy) {
if (searchText != null && !searchText.isEmpty()) {
BooleanQuery.Builder b = new BooleanQuery.Builder();
try (TokenStream stream = analyzer.tokenStream(FIELD_TERM, searchText)) {
CharTermAttribute termAtt = stream.addAttribute(CharTermAttribute.class);
stream.reset();
while (stream.incrementToken()) {
String s = termAtt.toString();
Term term = new Term("term", s);
Query tq = s.length() > MINIMUM_CHARS_FOR_FUZZY_SEARCH && fuzzy > 0 ? new FuzzyQuery(term, fuzzy) : new TermQuery(term);
if (s.length() >= MINIMUM_CHARS_FOR_PREFIX_SEARCH) {
PrefixQuery pq = new PrefixQuery(new Term("term", s));
pq.setRewriteMethod(PrefixQuery.SCORING_BOOLEAN_REWRITE);
BooleanQuery bq = new BooleanQuery.Builder().add(tq, Occur.SHOULD).add(pq, Occur.SHOULD).build();
b.add(bq, Occur.MUST);
}
else {
b.add(tq,Occur.MUST);
}
}
stream.end();
} catch (IOException e) {
e.printStackTrace();
}
return b.build();
}
return null;
}
示例4: getPrefixQuery
import org.apache.lucene.search.PrefixQuery; //导入方法依赖的package包/类
@Override
public Query getPrefixQuery(QParser parser, SchemaField sf, String termStr) {
if(termStr.equals("foo")) {
termStr = "bar";
} else if (termStr.equals("bar")) {
termStr = "foo";
}
PrefixQuery query = new PrefixQuery(new Term(sf.getName(), termStr));
query.setRewriteMethod(sf.getType().getRewriteMethod(parser, sf));
return query;
}
示例5: newPrefixQuery
import org.apache.lucene.search.PrefixQuery; //导入方法依赖的package包/类
/**
* Builds a new PrefixQuery instance
* @param prefix Prefix term
* @return new PrefixQuery instance
*/
protected Query newPrefixQuery(Term prefix){
PrefixQuery query = new PrefixQuery(prefix);
SchemaField sf = schema.getField(prefix.field());
query.setRewriteMethod(sf.getType().getRewriteMethod(parser, sf));
return query;
}
示例6: createPrefixQuery
import org.apache.lucene.search.PrefixQuery; //导入方法依赖的package包/类
@Override
public Query createPrefixQuery(final @NonNull String name, final @NonNull String value) {
final PrefixQuery pq = new PrefixQuery(new Term(name, value));
pq.setRewriteMethod(PrefixQuery.CONSTANT_SCORE_FILTER_REWRITE);
return pq;
}
示例7: newPrefixQuery
import org.apache.lucene.search.PrefixQuery; //导入方法依赖的package包/类
/**
* Builds a new PrefixQuery instance
*
* @param prefix Prefix term
* @return new PrefixQuery instance
*/
protected Query newPrefixQuery(Term prefix) {
PrefixQuery query = new PrefixQuery(prefix);
query.setRewriteMethod(multiTermRewriteMethod);
return query;
}
示例8: getPrefixQuery
import org.apache.lucene.search.PrefixQuery; //导入方法依赖的package包/类
/**
* Returns a Query instance for doing prefix searches on this field type.
* Also, other QueryParser implementations may have different semantics.
* <p/>
* Sub-classes should override this method to provide their own range query implementation.
*
* @param parser the {@link org.apache.solr.search.QParser} calling the method
* @param sf the schema field
* @param termStr the term string for prefix query
* @return a Query instance to perform prefix search
*
*/
public Query getPrefixQuery(QParser parser, SchemaField sf, String termStr) {
PrefixQuery query = new PrefixQuery(new Term(sf.getName(), termStr));
query.setRewriteMethod(sf.getType().getRewriteMethod(parser, sf));
return query;
}
示例9: newPrefixQuery
import org.apache.lucene.search.PrefixQuery; //导入方法依赖的package包/类
/**
* Builds a new PrefixQuery instance
*
* @param prefix
* Prefix term
* @return new PrefixQuery instance
*/
protected Query newPrefixQuery(Term prefix) {
PrefixQuery query = new PrefixQuery(prefix);
query.setRewriteMethod(multiTermRewriteMethod);
return query;
}