本文整理匯總了Java中org.apache.lucene.queryparser.classic.QueryParser.setDefaultOperator方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryParser.setDefaultOperator方法的具體用法?Java QueryParser.setDefaultOperator怎麽用?Java QueryParser.setDefaultOperator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.lucene.queryparser.classic.QueryParser
的用法示例。
在下文中一共展示了QueryParser.setDefaultOperator方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: query
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
Query query( String keyOrNull, Object value, QueryContext contextOrNull )
{
if ( value instanceof Query )
{
return (Query) value;
}
QueryParser parser = new QueryParser( keyOrNull, analyzer );
parser.setAllowLeadingWildcard( true );
parser.setLowercaseExpandedTerms( toLowerCase );
if ( contextOrNull != null && contextOrNull.getDefaultOperator() != null )
{
parser.setDefaultOperator( contextOrNull.getDefaultOperator() );
}
try
{
return parser.parse( value.toString() );
}
catch ( ParseException e )
{
throw new RuntimeException( e );
}
}
示例2: Navigator
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
/**
* Constructor
* @param indexRepo: the place the indices are stored
* @param improve: TODO
*/
public Navigator(String indexRepo, String filterFile, boolean ipv, boolean strict) {
indexReposity = indexRepo;
optimization = ipv;
try {
IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(indexReposity)));
searcher = new IndexSearcher(reader);
// analyzer = new StandardAnalyzer(Version.LUCENE_46);
// analyzer = new EnglishAnalyzer(Version.LUCENE_46);
analyzer = new CAnalyzer(Version.LUCENE_47).getAnalyzer();
parser = new QueryParser(Version.LUCENE_47, field, analyzer);
if(strict == true) {
parser.setDefaultOperator(QueryParser.AND_OPERATOR);
}
getMustSetOpts(filterFile);
} catch (IOException e) {
e.printStackTrace();
}
}
示例3: construct
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
@Override
protected Query construct(LindenQuery lindenQuery, LindenConfig config) throws IOException {
LindenQueryStringQuery stringQuery = lindenQuery.getQueryString();
QueryParser.Operator op = QueryParser.Operator.OR;
if (stringQuery.isSetOperator() && stringQuery.getOperator() == Operator.AND) {
op = QueryParser.Operator.AND;
}
QueryParser queryParser = new LindenQueryParser(config);
String content = stringQuery.getQuery();
try {
queryParser.setDefaultOperator(op);
Query query = queryParser.parse(content);
// disable coord
if (query instanceof BooleanQuery) {
BooleanQuery bQuery = (BooleanQuery) query;
BooleanQuery booleanQuery = new BooleanQuery(stringQuery.isDisableCoord());
BooleanClause[] clauses = bQuery.getClauses();
for (BooleanClause clause : clauses) {
booleanQuery.add(clause);
}
booleanQuery.setBoost(query.getBoost());
query = booleanQuery;
}
return query;
} catch (ParseException e) {
throw new IOException(Throwables.getStackTraceAsString(e));
}
}
示例4: test
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
@Test
public void test () throws ParseException
{
final QueryParser aQP = new QueryParser ("", PDLucene.createAnalyzer ());
aQP.setDefaultOperator (Operator.AND);
aQP.setAllowLeadingWildcard (true);
final Query aQuery = aQP.parse ("(allfields:*9905* AND allfields:*leckma*) AND NOT deleted:(*)");
System.out.println (aQuery.getClass () + " -- " + aQuery);
}
示例5: testLuceneSearch
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@Ignore
@Test
public void testLuceneSearch() {
try {
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_44);
Directory directory = FSDirectory.open(new File("/Users/Les.Westberg/Projects/vistacore/ehmp/product/production/hmp-main/data/termdb-1.UMLS2013AA.20131017-drugdb/lucene"));
DirectoryReader reader = DirectoryReader.open(directory);
IndexSearcher searcher = new IndexSearcher(reader);
QueryParser parser = new QueryParser(Version.LUCENE_44, "description", analyzer);
parser.setDefaultOperator(Operator.AND);
Query oQuery = new TermQuery(new Term("urn", "urn:vandf:4020400"));
TopDocs oTopDocs = searcher.search(oQuery, 100);
assertNotNull(oTopDocs);
for (ScoreDoc oScoreDoc : oTopDocs.scoreDocs) {
assertNotNull(oScoreDoc);
Document oDocument = reader.document(oScoreDoc.doc);
@SuppressWarnings("unused")
Document oDocument2 = searcher.doc(oScoreDoc.doc);
assertNotNull(oDocument);
}
}
catch (Exception e) {
System.out.println("An unhandled exception occurred. Error: " + e.getMessage());
e.printStackTrace();
fail("An unhandled exception occurred. Error: " + e.getMessage());
}
}
示例6: convertToLuceneQuery
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
@Override
public Query convertToLuceneQuery(@Nonnull UserProfileDataQuery query) {
final QueryParser parser = new MultiFieldQueryParser(LUCENE_VERSION, toFieldsArray(query), _luceneAnalyzerFactory.createAnalyzer());
parser.setDefaultOperator(AND);
final String searchTerm = query.getSearchTerm();
try {
return parser.parse(searchTerm != null ? searchTerm : "");
} catch (final ParseException e) {
throw new RuntimeException("Unable to parse query: " + searchTerm, e);
}
}
示例7: parse
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
@Override
public MiruFilter parse(String locale, boolean useStopWords, String queryString) throws Exception {
Analyzer analyzer = termAnalyzers.findAnalyzer(locale, useStopWords);
QueryParser parser = new QueryParser(defaultField, analyzer);
parser.setDefaultOperator(Operator.AND);
return makeFilter(parser.parse(queryString));
}
示例8: getParser
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
public QueryParser getParser(Analyzer a, Extensions extensions)
throws Exception {
if (a == null)
a = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true);
QueryParser qp = extensions == null ? new ExtendableQueryParser(
TEST_VERSION_CURRENT, getDefaultField(), a) : new ExtendableQueryParser(
TEST_VERSION_CURRENT, getDefaultField(), a, extensions);
qp.setDefaultOperator(QueryParserBase.OR_OPERATOR);
return qp;
}
示例9: parseConstraint
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
protected org.apache.lucene.search.Query parseConstraint(String q) {
Analyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_4_9);
QueryParser parser = new QueryParser(Version.LUCENE_4_9, schemaMapper.defaultField(), analyzer);
parser.setDefaultOperator(QueryParser.Operator.OR);
parser.setAllowLeadingWildcard(true);
try {
org.apache.lucene.search.Query result = parser.parse(q);
return result;
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
示例10: getCandidates
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
@Override
public CandidateInfo getCandidates(int queryNum,
Map<String, String> queryData,
int maxQty) throws Exception {
ArrayList<CandidateEntry> resArr = new ArrayList<CandidateEntry>();
String queryID = queryData.get(ID_FIELD_NAME);
if (null == queryID) {
throw new Exception(
String.format("Query id (%s) is undefined for query # %d",
ID_FIELD_NAME, queryNum));
}
String text = queryData.get(TEXT_FIELD_NAME);
if (null == text) {
throw new Exception(
String.format("Query (%s) is undefined for query # %d",
TEXT_FIELD_NAME, queryNum));
}
String query = text.trim();
ArrayList<String> toks = new ArrayList<String>();
for (String s: mSpaceSplit.split(query)) {
toks.add(s);
}
if (2 * toks.size() > BooleanQuery.getMaxClauseCount()) {
// This a heuristic, but it should work fine in many cases
BooleanQuery.setMaxClauseCount(2 * toks.size());
}
int numFound = 0;
if (!query.isEmpty()) {
// QueryParser cannot be shared among threads!
QueryParser parser = new QueryParser(TEXT_FIELD_NAME, mAnalyzer);
parser.setDefaultOperator(QueryParser.OR_OPERATOR);
Query queryParsed = parser.parse(query);
TopDocs hits = mSearcher.search(queryParsed, maxQty);
numFound = hits.totalHits;
ScoreDoc[] scoreDocs = hits.scoreDocs;
for (ScoreDoc oneHit: scoreDocs) {
Document doc = mSearcher.doc(oneHit.doc);
String id = doc.get(ID_FIELD_NAME);
float score = oneHit.score;
resArr.add(new CandidateEntry(id, score));
}
}
CandidateEntry[] results = resArr.toArray(new CandidateEntry[resArr.size()]);
Arrays.sort(results);
return new CandidateInfo(numFound, results);
}