Package org.apache.lucene.search

Examples of org.apache.lucene.search.Query


    writer.close();

    IndexReader reader = IndexReader.open(ramDir);
    String queryString = QUERY;
    QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, FIELD_NAME, analyzer);
    Query query = parser.parse(queryString);
    Searcher searcher = new IndexSearcher(ramDir);
    query = query.rewrite(reader);
    System.out.println("Searching for: " + query.toString(FIELD_NAME));
    TopDocs hits = searcher.search(query, 10);

    BoldFormatter formatter = new BoldFormatter();
    Highlighter highlighter = new Highlighter(formatter, new QueryScorer(
        query));
View Full Code Here


    writer.close();

    IndexReader reader = IndexReader.open(ramDir);
    String queryString = QUERY;
    QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, FIELD_NAME, analyzer);
    Query query = parser.parse(queryString);
    Searcher searcher = new IndexSearcher(ramDir);
    query = query.rewrite(reader);
    System.out.println("Searching for: " + query.toString(FIELD_NAME));
    TopDocs hits = searcher.search(query, 10);   

    BoldFormatter formatter = new BoldFormatter();
    Highlighter highlighter = new Highlighter(formatter, new QueryScorer(
        query));
View Full Code Here

      //截取头部^尾部$
      keyword = keyword.substring(1 , keyword.length() - 1);
      String luceneExp = fieldName + ":\"" + keyword + "\"";
      QueryParser luceneQueryParser = new QueryParser(Version.LUCENE_30 , "" ,new IKAnalyzer());
      try {
        Query lucenceQuery = luceneQueryParser.parse(luceneExp);
        return lucenceQuery;
      } catch (ParseException e) {
        e.printStackTrace();
      }               
      return null;     
View Full Code Here

      throw new IllegalArgumentException("parameter \"fields\" is null");
    }   
    BooleanQuery resultQuery = new BooleanQuery();   
    for(String field : fields){
      if(field != null){
        Query partQuery = parse(field , query);
        if(partQuery != null &&
                  (!(partQuery instanceof BooleanQuery) || ((BooleanQuery)partQuery).getClauses().length>0)){
          resultQuery.add(partQuery, Occur.SHOULD);
        }
      }     
View Full Code Here

    }   
   
    BooleanQuery resultQuery = new BooleanQuery();   
    for(int i = 0; i < fields.length; i++){
      if(fields[i] != null){
        Query partQuery = parse(fields[i] , query);
        if(partQuery != null &&
                  (!(partQuery instanceof BooleanQuery) || ((BooleanQuery)partQuery).getClauses().length>0)){
          resultQuery.add(partQuery, flags[i]);
        }
      }     
View Full Code Here

          throw new IllegalArgumentException("queries.length != fields.length");
    }
    BooleanQuery resultQuery = new BooleanQuery();   
    for(int i = 0; i < fields.length; i++){
      if(fields[i] != null){
        Query partQuery = parse(fields[i] , queries[i]);
        if(partQuery != null &&
                  (!(partQuery instanceof BooleanQuery) || ((BooleanQuery)partQuery).getClauses().length>0)){
          resultQuery.add(partQuery, Occur.SHOULD);
        }
      }     
View Full Code Here

      }

      BooleanQuery resultQuery = new BooleanQuery();   
    for(int i = 0; i < fields.length; i++){
      if(fields[i] != null){
        Query partQuery = parse(fields[i] , queries[i]);
        if(partQuery != null &&
                  (!(partQuery instanceof BooleanQuery) || ((BooleanQuery)partQuery).getClauses().length>0)){
          resultQuery.add(partQuery, flags[i]);
        }
      }     
View Full Code Here

    }
  }
  public static void main(String[] args){
    String ikQueryExp = "(id='ABcdRf' && date:{'20010101','20110101'} && keyword:'^魔兽中国$') || (content:'魔兽 中国'  || ulr='www.ik.com') - name:'林良益'";
//    String ikQueryExp = "content:'----'  || title:'----' - name:'林良益'";
    Query result = IKQueryParser.parse(ikQueryExp);
//    Query result = IKQueryParser.parse("(newsKeyword='---' || newsTitle:'---' || newsContent:'---') && newsClass='1'");
    System.out.println(result);

 
View Full Code Here

        queries.add(new TermQuery(new Term(fieldName , lexeme.getLexemeText())));
      }     
      //生成child branch 的query
      if(acceptedBranchs != null && acceptedBranchs.size() > 0){
        if(acceptedBranchs.size() == 1){
          Query onlyOneQuery = optimizeQueries(acceptedBranchs.get(0).toQueries(fieldName));
          if(onlyOneQuery != null){
            queries.add(onlyOneQuery);
          }         
        }else{
          BooleanQuery orQuery = new BooleanQuery();
          for(TokenBranch childBranch : acceptedBranchs){
            Query childQuery = optimizeQueries(childBranch.toQueries(fieldName));
            if(childQuery != null){
              orQuery.add(childQuery, Occur.SHOULD);
            }
          }
          if(orQuery.getClauses().length > 0){
View Full Code Here

      isearcher.setSimilarity(new IKSimilarity());
     
      String keyword = "中文分词工具包";
     
      //使用IKQueryParser查询分析器构造Query对象
      Query query = IKQueryParser.parse(fieldName, keyword);
     
      //搜索相似度最高的5条记录
      TopDocs topDocs = isearcher.search(query , 5);
      System.out.println("命中:" + topDocs.totalHits);
      //输出结果
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.Query

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.