本文整理汇总了Java中org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler类的典型用法代码示例。如果您正苦于以下问题:Java StandardQueryConfigHandler类的具体用法?Java StandardQueryConfigHandler怎么用?Java StandardQueryConfigHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StandardQueryConfigHandler类属于org.apache.lucene.queryparser.flexible.standard.config包,在下文中一共展示了StandardQueryConfigHandler类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testStopWordSearching
import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler; //导入依赖的package包/类
public void testStopWordSearching() throws Exception {
Analyzer analyzer = new MockAnalyzer(random());
Directory ramDir = newDirectory();
IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(analyzer));
Document doc = new Document();
doc.add(newTextField("body", "blah the footest blah", Field.Store.NO));
iw.addDocument(doc);
iw.close();
StandardQueryParser mfqp = new StandardQueryParser();
mfqp.setMultiFields(new String[] { "body" });
mfqp.setAnalyzer(analyzer);
mfqp.setDefaultOperator(StandardQueryConfigHandler.Operator.AND);
Query q = mfqp.parse("the footest", null);
IndexReader ir = DirectoryReader.open(ramDir);
IndexSearcher is = newSearcher(ir);
ScoreDoc[] hits = is.search(q, null, 1000).scoreDocs;
assertEquals(1, hits.length);
ir.close();
ramDir.close();
}
示例2: testStopWordSearching
import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler; //导入依赖的package包/类
public void testStopWordSearching() throws Exception {
Analyzer analyzer = new MockAnalyzer(random());
Directory ramDir = newDirectory();
IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
Document doc = new Document();
doc.add(newTextField("body", "blah the footest blah", Field.Store.NO));
iw.addDocument(doc);
iw.close();
StandardQueryParser mfqp = new StandardQueryParser();
mfqp.setMultiFields(new String[] { "body" });
mfqp.setAnalyzer(analyzer);
mfqp.setDefaultOperator(StandardQueryConfigHandler.Operator.AND);
Query q = mfqp.parse("the footest", null);
IndexReader ir = DirectoryReader.open(ramDir);
IndexSearcher is = new IndexSearcher(ir);
ScoreDoc[] hits = is.search(q, null, 1000).scoreDocs;
assertEquals(1, hits.length);
ir.close();
ramDir.close();
}
示例3: testStopWordSearching
import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler; //导入依赖的package包/类
public void testStopWordSearching() throws Exception {
Analyzer analyzer = new MockAnalyzer(random());
Directory ramDir = newDirectory();
IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
Document doc = new Document();
doc.add(newTextField("body", "blah the footest blah", Field.Store.NO));
iw.addDocument(doc);
iw.close();
StandardQueryParser mfqp = new StandardQueryParser();
mfqp.setMultiFields(new String[] { "body" });
mfqp.setAnalyzer(analyzer);
mfqp.setDefaultOperator(StandardQueryConfigHandler.Operator.AND);
Query q = mfqp.parse("the footest", null);
IndexReader ir = DirectoryReader.open(ramDir);
IndexSearcher is = newSearcher(ir);
ScoreDoc[] hits = is.search(q, null, 1000).scoreDocs;
assertEquals(1, hits.length);
ir.close();
ramDir.close();
}
示例4: getKeywords
import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler; //导入依赖的package包/类
public static List<String> getKeywords(final String q, final String[] fields) {
final List<String> keywords = new ArrayList<>();
final List<TermQuery> termQueryList;
try {
final StandardQueryParser parser = new StandardQueryParser();
parser.setDefaultOperator(StandardQueryConfigHandler.Operator.AND);
termQueryList = getTermQueryList(parser.parse(q, "default"), fields);
} catch (final Exception e) {
return keywords;
}
for (final TermQuery tq : termQueryList) {
final String text = tq.getTerm().text();
if (0 == text.length()) {
continue;
}
if (keywords.contains(text)) {
continue;
}
keywords.add(text);
}
return keywords;
}
示例5: process
import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler; //导入依赖的package包/类
@Override
public QueryNode process(QueryNode queryTree) throws QueryNodeException {
Operator op = getQueryConfigHandler().get(ConfigurationKeys.DEFAULT_OPERATOR);
if (op == null) {
throw new IllegalArgumentException(
"StandardQueryConfigHandler.ConfigurationKeys.DEFAULT_OPERATOR should be set on the QueryConfigHandler");
}
this.usingAnd = StandardQueryConfigHandler.Operator.AND == op;
return super.process(queryTree);
}
示例6: process
import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler; //导入依赖的package包/类
@Override
public QueryNode process(QueryNode queryTree) throws QueryNodeException {
Operator op = getQueryConfigHandler().get(
ConfigurationKeys.DEFAULT_OPERATOR);
if (op == null) {
throw new IllegalArgumentException(
"StandardQueryConfigHandler.ConfigurationKeys.DEFAULT_OPERATOR should be set on the QueryConfigHandler");
}
this.usingAnd = StandardQueryConfigHandler.Operator.AND == op;
return processIteration(queryTree);
}
示例7: StandardQueryParser
import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler; //导入依赖的package包/类
/**
* Constructs a {@link StandardQueryParser} object.
*/
public StandardQueryParser() {
super(new StandardQueryConfigHandler(), new StandardSyntaxParser(),
new StandardQueryNodeProcessorPipeline(null),
new StandardQueryTreeBuilder());
setEnablePositionIncrements(true);
}
示例8: getParser
import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler; //导入依赖的package包/类
public PrecedenceQueryParser getParser(Analyzer a) throws Exception {
if (a == null)
a = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true);
PrecedenceQueryParser qp = new PrecedenceQueryParser();
qp.setAnalyzer(a);
qp.setDefaultOperator(StandardQueryConfigHandler.Operator.OR);
return qp;
}
示例9: getQueryDOA
import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler; //导入依赖的package包/类
public Query getQueryDOA(String query, Analyzer a) throws Exception {
if (a == null)
a = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true);
PrecedenceQueryParser qp = new PrecedenceQueryParser();
qp.setAnalyzer(a);
qp.setDefaultOperator(StandardQueryConfigHandler.Operator.AND);
return qp.parse(query, "field");
}
示例10: testDefaultOperator
import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler; //导入依赖的package包/类
@Override
public void testDefaultOperator() throws Exception {
StandardQueryParser qp = getParser(new MockAnalyzer(random()));
// make sure OR is the default:
assertEquals(StandardQueryConfigHandler.Operator.OR, qp.getDefaultOperator());
setDefaultOperatorAND(qp);
assertEquals(StandardQueryConfigHandler.Operator.AND, qp.getDefaultOperator());
setDefaultOperatorOR(qp);
assertEquals(StandardQueryConfigHandler.Operator.OR, qp.getDefaultOperator());
}
示例11: getParser
import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler; //导入依赖的package包/类
public StandardQueryParser getParser(Analyzer a) throws Exception {
if (a == null)
a = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true);
StandardQueryParser qp = new StandardQueryParser();
qp.setAnalyzer(a);
qp.setDefaultOperator(StandardQueryConfigHandler.Operator.OR);
return qp;
}
示例12: getQueryDOA
import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler; //导入依赖的package包/类
public Query getQueryDOA(String query, Analyzer a) throws Exception {
if (a == null)
a = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true);
StandardQueryParser qp = new StandardQueryParser();
qp.setAnalyzer(a);
qp.setDefaultOperator(StandardQueryConfigHandler.Operator.AND);
return qp.parse(query, "field");
}