當前位置: 首頁>>代碼示例>>Java>>正文


Java QueryParser.setDefaultOperator方法代碼示例

本文整理匯總了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 );
    }
}
 
開發者ID:neo4j-contrib,項目名稱:neo4j-lucene5-index,代碼行數:24,代碼來源:IndexType.java

示例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();
	}
}
 
開發者ID:tianyin,項目名稱:cox,代碼行數:28,代碼來源:Navigator.java

示例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));
  }
}
 
開發者ID:XiaoMi,項目名稱:linden,代碼行數:29,代碼來源:QueryStringQueryConstructor.java

示例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);
}
 
開發者ID:phax,項目名稱:peppol-directory,代碼行數:10,代碼來源:QueryParserFuncTest.java

示例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());
	}
}
 
開發者ID:KRMAssociatesInc,項目名稱:eHMP,代碼行數:32,代碼來源:LuceneUtilTest.java

示例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);
    }
}
 
開發者ID:echocat,項目名稱:adam,代碼行數:12,代碼來源:UserProfileDataQueryMapper.java

示例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));
}
 
開發者ID:jivesoftware,項目名稱:miru,代碼行數:8,代碼來源:LuceneBackedQueryParser.java

示例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;
}
 
開發者ID:pkarmstr,項目名稱:NYBC,代碼行數:11,代碼來源:TestExtendableQueryParser.java

示例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);
        }
    }
 
開發者ID:scaleset,項目名稱:scaleset-search,代碼行數:14,代碼來源:MongoQueryConverter.java

示例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);
}
 
開發者ID:oaqa,項目名稱:knn4qa,代碼行數:60,代碼來源:LuceneCandidateProvider.java


注:本文中的org.apache.lucene.queryparser.classic.QueryParser.setDefaultOperator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。