当前位置: 首页>>代码示例>>Java>>正文


Java QueryParser.setDefaultOperator方法代码示例

本文整理汇总了Java中org.apache.lucene.queryParser.QueryParser.setDefaultOperator方法的典型用法代码示例。如果您正苦于以下问题:Java QueryParser.setDefaultOperator方法的具体用法?Java QueryParser.setDefaultOperator怎么用?Java QueryParser.setDefaultOperator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.queryParser.QueryParser的用法示例。


在下文中一共展示了QueryParser.setDefaultOperator方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processArgument

import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
@Override
protected boolean processArgument(String arg) throws CLIOException {
	try {
		Analyzer analyzer = PubMedIndexUtils.getGlobalAnalyzer();
		QueryParser parser = new QueryParser(PubMedIndexUtils.LUCENE_VERSION, PubMedIndexField.ABSTRACT.fieldName, analyzer);
		parser.setDefaultOperator(QueryParser.AND_OPERATOR);
		parser.setLowercaseExpandedTerms(false);
		PubMedIndexUtils.log("parsing query: %s", arg);
		Query q = parser.parse(arg);
		PubMedIndexUtils.log("query: %s", q);
		addClause(q);
		return false;
	}
	catch (ParseException e) {
		throw new CLIOException(e);
	}
}
 
开发者ID:Bibliome,项目名称:bibliome-java-utils,代码行数:18,代码来源:PubMedIndexSearcher.java

示例2: select

import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
/**
  * Executes a select query.
  * @param query The Lucene query
  * @return An array of record IDs; an empty array if an error occured
* @throws IOException 
  */
 public int[] select(String query, String sortPrefix)  throws ParseException{
   try {
     WhitespaceAnalyzer sa= new WhitespaceAnalyzer();
     BooleanQuery.setMaxClauseCount(20000);//zbog heap-a
     QueryParser p = new QueryParser("KW", sa);
     p.setDefaultOperator(QueryParser.Operator.AND); //default operator je AND a ne OR kao sto je inace inicijalno
     Query q = p.parse(query);
     return select(q, sortPrefix);
   } catch (Exception ex) {
   	if (ex instanceof ParseException )
   		throw (ParseException)ex;
     log.warn(ex);
     return new int[0];
   }
 }
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:22,代码来源:Retriever.java

示例3: getSubQueryFilters

import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
/**
 * Execute the sub query facets and return the search results
 * @throws ParseException 
 * @throws IOException 
 */
private List<Filter> getSubQueryFilters( List<FacetFilter> filters, 
		IndexSearcher searcher) throws ParseException, IOException
{
	List<Filter> luceneFilters = new LinkedList<Filter>();
	
	for(FacetFilter filter : filters)
	{	
		if(log.isDebugEnabled())
		{
			log.debug("adding filter for field " + filter.getField() + " and query " + filter.getQuery());
		}
	    QueryParser subQueryParser = new QueryParser(Version.LUCENE_35, filter.getField(), analyzer);
	    subQueryParser.setDefaultOperator(QueryParser.AND_OPERATOR);
	    String fixedQuery = SearchHelper.prepareFacetSearchString(filter.getQuery(), false);
	    fixedQuery = "\"" + fixedQuery + "\"";
	    Query subQuery = subQueryParser.parse(fixedQuery);
	    if(log.isDebugEnabled())
		{
			log.debug("sub query ing getSubQueryFilters is " + fixedQuery);
		}
	    luceneFilters.add(new QueryWrapperFilter(subQuery));
	}
	
	return luceneFilters;
}
 
开发者ID:nate-rcl,项目名称:irplus,代码行数:31,代码来源:DefaultResearcherSearchService.java

示例4: query

import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
Query query( String keyOrNull, Object value, QueryContext contextOrNull )
{
    if ( value instanceof Query )
    {
        return (Query) value;
    }
    
    QueryParser parser = new QueryParser( Version.LUCENE_30, 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-mobile-android,代码行数:24,代码来源:IndexType.java

示例5: search

import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public Page<Article> search(String keyword, Pageable pageable) {
	if (StringUtils.isEmpty(keyword)) {
		return new Page<Article>();
	}
	if (pageable == null) {
		pageable = new Pageable();
	}
	try {
		String text = QueryParser.escape(keyword);
		QueryParser titleParser = new QueryParser(Version.LUCENE_35, "title", new IKAnalyzer());
		titleParser.setDefaultOperator(QueryParser.AND_OPERATOR);
		Query titleQuery = titleParser.parse(text);
		FuzzyQuery titleFuzzyQuery = new FuzzyQuery(new Term("title", text), FUZZY_QUERY_MINIMUM_SIMILARITY);
		Query contentQuery = new TermQuery(new Term("content", text));
		Query isPublicationQuery = new TermQuery(new Term("isPublication", "true"));
		BooleanQuery textQuery = new BooleanQuery();
		BooleanQuery query = new BooleanQuery();
		textQuery.add(titleQuery, Occur.SHOULD);
		textQuery.add(titleFuzzyQuery, Occur.SHOULD);
		textQuery.add(contentQuery, Occur.SHOULD);
		query.add(isPublicationQuery, Occur.MUST);
		query.add(textQuery, Occur.MUST);
		FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
		FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(query, Article.class);
		fullTextQuery.setSort(new Sort(new SortField[] { new SortField("isTop", SortField.STRING, true), new SortField(null, SortField.SCORE), new SortField("createDate", SortField.LONG, true) }));
		fullTextQuery.setFirstResult((pageable.getPageNumber() - 1) * pageable.getPageSize());
		fullTextQuery.setMaxResults(pageable.getPageSize());
		return new Page<Article>(fullTextQuery.getResultList(), fullTextQuery.getResultSize(), pageable);
	} catch (ParseException e) {
		e.printStackTrace();
	}
	return new Page<Article>();
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:36,代码来源:SearchServiceImpl.java

示例6: search

import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
/**
 * 检索
 *
 * @param keyword
 */
public static void search(String keyword) throws Exception {

    IndexSearcher searcher = null;

    try {
        // 创建search
        searcher = getIndexSearcher();

        String[] fields = { "name", "author", "content" };
        QueryParser queryParser = new MultiFieldQueryParser(Version.LUCENE_35, fields,
            new StandardAnalyzer(Version.LUCENE_35));
        queryParser.setDefaultOperator(QueryParser.AND_OPERATOR);
        Query query = queryParser.parse(keyword);

        // 查询
        TopDocs topDocs = searcher.search(query, MAX);

        ScoreDoc[] scoreDocs = topDocs.scoreDocs;
        logger.info("查询到条数=" + scoreDocs.length);

        for (ScoreDoc scoreDoc : scoreDocs) {
            Document doc = searcher.doc(scoreDoc.doc);
            logger.info("doc信息:" + "docId=" + scoreDoc.doc + "id=" + doc.get("id") + "author="
                        + doc.get("author") + "name=" + doc.get("name") + "content="
                        + doc.get("content"));
        }

    } catch (Exception e) {
        logger.error("查询失败:" + e.getMessage());
        throw e;
    }
}
 
开发者ID:cycman,项目名称:libooc,代码行数:38,代码来源:IndexUtil.java

示例7: multiFieldQuery

import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
/**
     * 多条搜索
     * @param fields
     * @param value
     * @throws Exception
     */
    public static void multiFieldQuery( String[] fields, String value,List<Document>docs) throws Exception {
        try {

        	
            // 创建search
            IndexSearcher searcher = getIndexSearcher();


            QueryParser queryParser = new MultiFieldQueryParser(Version.LUCENE_35, fields,
                    new StandardAnalyzer(Version.LUCENE_35));

            queryParser.setDefaultOperator(QueryParser.AND_OPERATOR);
            Query query = queryParser.parse(value);

            // 查询
            
            TopDocs topDocs = searcher.search(query, 1000);

            ScoreDoc[] scoreDocs = topDocs.scoreDocs;
            logger.info("查询到条数=" + scoreDocs.length);

            for (ScoreDoc scoreDoc : scoreDocs) {
                Document doc = searcher.doc(scoreDoc.doc);
//                logger.info("doc信息:" + " docId=" + scoreDoc.doc + " id=" + doc.get("id") + " author="
//                        + doc.get("author") + " name=" + doc.get("name") + " content="
//                        + doc.get("content"));
                docs.add(doc);
            }
        } catch (Exception e) {
            logger.error("termQuery查询失败");
            throw e;
        }
    }
 
开发者ID:cycman,项目名称:libooc,代码行数:40,代码来源:SearchUtil.java

示例8: getQueryParser

import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
private final QueryParser getQueryParser( QueryDef qd ){
    QueryParser toReturn;
    if ( qd.boosts == null || qd.boosts.isEmpty( ) )
        toReturn = new SpecialMultiFieldQueryParser( LUCENEVERSION, qd.fields, analyzer );
    else
        toReturn = new SpecialMultiFieldQueryParser( LUCENEVERSION, qd.fields, analyzer, qd.boosts );
    toReturn.setDefaultOperator( defaultOperator );

    return toReturn;
}
 
开发者ID:webdsl,项目名称:webdsl,代码行数:11,代码来源:AbstractEntitySearcher.java

示例9: processFacetCategory

import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
/**
 * Determines the number of hits for each facet across the main query.
 * 
 * @param facets
 * @param reader
 * @param mainQueryBits
 * @throws ParseException
 * @throws IOException
 */
private void processFacetCategory(Collection<FacetResult> facets, 
		IndexReader reader, 
		DocIdSet mainQueryBits) 
   throws ParseException, IOException
{
	for(FacetResult f : facets )
	{
		QueryParser subQueryParser = new QueryParser(Version.LUCENE_35, f.getField(), analyzer);
		subQueryParser.setDefaultOperator(QueryParser.AND_OPERATOR);
		String fixedQuery = SearchHelper.prepareFacetSearchString(f.getFacetName(), false);
		fixedQuery = "\"" + fixedQuery + "\"";
		Query subQuery = subQueryParser.parse(fixedQuery);
		
		if(log.isDebugEnabled())
		{
			log.debug("Fiexed query in process Facet Category = " + fixedQuery);
		}
		
		QueryWrapperFilter subQueryWrapper = new QueryWrapperFilter(subQuery);
	    DocIdSet subQueryBits = subQueryWrapper.getDocIdSet(reader);
	
	    OpenBitSetDISI mainQuerybitSet = new OpenBitSetDISI(mainQueryBits.iterator(), maxNumberOfMainQueryHits);
	    OpenBitSetDISI subQuerybitSet = new OpenBitSetDISI(subQueryBits.iterator(), maxNumberOfMainQueryHits);
		
		long count = getFacetHitCount(mainQuerybitSet, subQuerybitSet);
		f.setHits(count);
	}
}
 
开发者ID:nate-rcl,项目名称:irplus,代码行数:38,代码来源:DefaultResearcherSearchService.java

示例10: selectAll1

import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
public Result selectAll1(String query, String sortPrefix)throws ParseException{
  try {
  	WhitespaceAnalyzer sa= new WhitespaceAnalyzer();
  	Searcher searcher = new IndexSearcher(indexPath);
      BooleanQuery.setMaxClauseCount(20000);//zbog heap-a
      QueryParser p = new QueryParser("KW", sa);
      p.setDefaultOperator(QueryParser.Operator.AND); //default operator je AND a ne OR kao sto je inace inicijalno
      Query q = p.parse(query);
      Hits hits;
    if (sortPrefix == null || "".equals(sortPrefix))
      hits = searcher.search(q);
    else {
      int sortType = SortField.STRING;
      if ("RN_sort".equals(sortPrefix))
        sortType = SortField.INT;
      hits = searcher.search(q, new Sort(
          new SortField(sortPrefix, sortType)));
    }
    
    int n = hits.length();
    int[] retVal = new int[n];
    List<String> invs = new ArrayList<String>();
    Field[] tmp = null;
    
    for (int i = 0; i < n; i++) {
      String recordID = hits.doc(i).get("ID");
      retVal[i] = Integer.parseInt(recordID);
      tmp = hits.doc(i).getFields("IN");
      if (tmp != null){
        for (int j = 0; j<tmp.length; j++){
          invs.add(tmp[j].stringValue());
        } 
      }
    }
    searcher.close();
    Result result = new Result();
    result.setRecords(retVal);
    result.setInvs(invs);
    return result;
  } catch (Exception ex) {
  	if (ex instanceof ParseException )
  		throw (ParseException)ex;
    log.fatal(ex);
    return null;
  }
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:47,代码来源:Retriever.java

示例11: executeSearchWithFacets

import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
/**
 * Get the facets and results
 * @see edu.ur.ir.institution.InstitutionalItemSearchService#executeSearchWithFacets(java.lang.String, java.lang.String, int, int, int, int)
 */
public FacetSearchHelper executeSearchWithFacets(
		String mainQueryString,
		String indexFolder, 
		int numberOfHitsToProcessForFacets, 
		int numberOfResultsToCollectForFacets,
		int numberOfFactsToShow,
		int numberOfIdsToCollect,
		int idsToCollectStartPosition ) 
        throws CorruptIndexException, IOException, ParseException 
{
	log.debug("orginal query 4 = " + mainQueryString);
	if( searchDirectoryIsEmpty(indexFolder) || isInvalidQuery(mainQueryString))
	{
		return new FacetSearchHelper(new HashSet<Long>(), 0, new HashMap<String, Collection<FacetResult>>(), mainQueryString);
	}
	
	FSDirectory directory = FSDirectory.open(new File(indexFolder));
	IndexReader reader = IndexReader.open(directory, true);
	IndexSearcher searcher = new IndexSearcher(reader);
	
	
	QueryParser parser = new MultiFieldQueryParser(Version.LUCENE_35, fields, analyzer, getBoostedFields());
	parser.setDefaultOperator(QueryParser.AND_OPERATOR);
	
	// execute the main query - we will use this to extract data to determine the facet searches
	// the search helper MUST BE SET TO FALSE if diacritic based searches are to work
	// putting a * following a diacritic does not work
	String executedQuery = SearchHelper.prepareMainSearchString(mainQueryString, false);
	Query mainQuery = parser.parse(executedQuery);
	if( log.isDebugEnabled() )
	{
		log.debug("main query = " + executedQuery );
		log.debug("main query parsed = " + mainQuery + " maxNumberOfMainQueryHits = " + maxNumberOfMainQueryHits );
	}
	
	
	TopDocs topDocs = searcher.search(mainQuery,  maxNumberOfMainQueryHits);
	
	// determine the set of data we should use to determine facets
	HashMap<String, HashMap<String, FacetResult>> possibleFacets = this.generateFacetSearches(
			topDocs, 
			numberOfHitsToProcessForFacets, 
			numberOfResultsToCollectForFacets,
			searcher);

	QueryWrapperFilter mainQueryWrapper = new QueryWrapperFilter(mainQuery);
	log.debug("executeSearchWithFacets 1 query = " + mainQuery);
	DocIdSet mainQueryBits = mainQueryWrapper.getDocIdSet(reader);
	OpenBitSetDISI mainQueryBitSet = new OpenBitSetDISI(mainQueryBits.iterator(), reader.maxDoc());
	
	
	HashMap<String, Collection<FacetResult>> facetResults = new HashMap<String, Collection<FacetResult>>();
	
	// process the data and determine the facets
       FacetSearchHelper helper = processPossibleFacets(possibleFacets, 
       		reader, 
       		mainQueryBitSet, 
       		facetResults, 
       		topDocs, 
       		numberOfIdsToCollect, 
       		idsToCollectStartPosition,
       		numberOfFactsToShow,
       		mainQueryString,
       		searcher);
	helper.setExecutedQuery(executedQuery);
       searcher.close();
       reader.close();
       return helper;
}
 
开发者ID:nate-rcl,项目名称:irplus,代码行数:74,代码来源:DefaultInstitutionalItemSearchService.java

示例12: executeSearchWithFacets

import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
/**
 * Get the facets and results
 * @see edu.ur.ir.researcher.ResearcherSearchService#executeSearchWithFacets(java.lang.String, java.lang.String, int, int, int, int)
 */
public FacetSearchHelper executeSearchWithFacets(
		String mainQueryString,
		String indexFolder, 
		int numberOfHitsToProcessForFacets, 
		int numberOfResultsToCollectForFacets,
		int numberOfFactsToShow,
		int numberOfIdsToCollect,
		int idsToCollectStartPosition ) 
        throws CorruptIndexException, IOException, ParseException 
{
	if( searchDirectoryIsEmpty(indexFolder) || isInvalidQuery(mainQueryString))
	{
		return new FacetSearchHelper(new HashSet<Long>(), 0, new HashMap<String, Collection<FacetResult>>(), mainQueryString);
	}
	
	FSDirectory directory = FSDirectory.open(new File(indexFolder));
	IndexReader reader = IndexReader.open(directory);
	IndexSearcher searcher = new IndexSearcher(reader);
	
	QueryParser parser = new MultiFieldQueryParser(Version.LUCENE_35, fields, analyzer);
	parser.setDefaultOperator(QueryParser.AND_OPERATOR);
	
	
	HashMap<String, Collection<FacetResult>> facetResults = new HashMap<String, Collection<FacetResult>>();
	
	// execute the main query - we will use this to extract data to determine the facet searches
	String executedQuery = SearchHelper.prepareMainSearchString(mainQueryString, true);
	Query mainQuery = parser.parse(executedQuery);
	if( log.isDebugEnabled() )
	{
		log.debug("main query = " + executedQuery );
	}
	
	TopDocs hits = searcher.search(mainQuery, maxNumberOfMainQueryHits);
	
	// determine the set of data we should use to determine facets
	HashMap<String, HashMap<String, FacetResult>> possibleFacets = this.generateFacetSearches(hits, 
			numberOfHitsToProcessForFacets, 
			numberOfResultsToCollectForFacets,
			searcher);

	QueryWrapperFilter mainQueryWrapper = new QueryWrapperFilter(mainQuery);
	log.debug("executeSearchWithFacets 1 query = " + mainQuery);
	
    // get the bitset for main query
	DocIdSet mainQueryBits = mainQueryWrapper.getDocIdSet(reader);
	

	// process the data and determine the facets
       FacetSearchHelper helper = this.processPossibleFacets(possibleFacets, 
       		reader, 
       		mainQueryBits, 
       		facetResults, 
       		hits, 
       		numberOfIdsToCollect, 
       		idsToCollectStartPosition,
       		numberOfFactsToShow,
       		mainQueryString, 
       		searcher);
	helper.setExecutedQuery(executedQuery);
       searcher.close();
       reader.close();
       return helper;
}
 
开发者ID:nate-rcl,项目名称:irplus,代码行数:69,代码来源:DefaultResearcherSearchService.java

示例13: getQuery

import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
private Query getQuery(final String field, final String query) throws ParseException {
    final QueryParser queryParser = new QueryParser(LUCENE_VERSION, field, analyzer);
    queryParser.setAllowLeadingWildcard(true);
    queryParser.setDefaultOperator(QueryParser.Operator.AND);
    return queryParser.parse(query);
}
 
开发者ID:JetBrains,项目名称:xodus,代码行数:7,代码来源:ExodusLuceneWithPatriciaTests.java

示例14: parse

import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
public static Query parse(String field, String value, Operator op){
    QueryParser parser = new QueryParser(BuguIndex.getInstance().getVersion(), field, BuguIndex.getInstance().getAnalyzer());
    parser.setDefaultOperator(op);
    return parse(parser, value);
}
 
开发者ID:xbwen,项目名称:bugu-mongo,代码行数:6,代码来源:BuguParser.java


注:本文中的org.apache.lucene.queryParser.QueryParser.setDefaultOperator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。