Package org.apache.lucene.search

Examples of org.apache.lucene.search.Query


     *
     * @param expression
     * @return
     */
    public Query parserExp(String expression){
      Query lucenceQuery = null;
      try{
        //文法解析
        this.splitElements(expression);
        //语法解析
        this.parseSyntax();
View Full Code Here


              TermQuery tQuery = new TermQuery(new Term(e.toString() , e3.toString()));
              this.querys.push(tQuery);
            }else if(':' == e2.type){
              String keyword = e3.toString();
              if(keyword.startsWith("^") && keyword.endsWith("$")){
                Query pQuery = this.luceneQueryParse(e.toString(), keyword);
                this.querys.push(pQuery);
              }else{
                Query tQuery = IKQueryParser.parse(e.toString(), e3.toString());
                this.querys.push(tQuery);
              }
            }
           
          }else if('[' == e3.type || '{' == e3.type){
            i+=2;
            //处理 [] 和 {}
            LinkedList<Element> eQueue = new LinkedList<Element>();
            eQueue.add(e3);
            for( i++ ; i < this.elements.size() ; i++){             
              Element eN = this.elements.get(i);
              eQueue.add(eN);
              if(']' == eN.type || '}' == eN.type){
                break;
              }
            }
            //翻译RangeQuery
            Query rangeQuery = this.toTermRangeQuery(e , eQueue);
            this.querys.push(rangeQuery);
          }else{
            throw new IllegalStateException("表达式异常:匹配值丢失");
          }
         
        }else if('(' == e.type){
          this.operates.push(e);
         
        }else if(')' == e.type){
          boolean doPop = true;
          while(doPop && !this.operates.empty()){
            Element op = this.operates.pop();
            if('(' == op.type){
              doPop = false;
            }else {
              Query q = toQuery(op);
              this.querys.push(q);
            }
           
          }
        }else{
         
          if(this.operates.isEmpty()){
            this.operates.push(e);
          }else{
            boolean doPeek = true;
            while(doPeek && !this.operates.isEmpty()){
              Element eleOnTop = this.operates.peek();
              if('(' == eleOnTop.type){
                doPeek = false;
                this.operates.push(e);
              }else if(compare(e , eleOnTop) == 1){
                this.operates.push(e);
                doPeek = false;
              }else if(compare(e , eleOnTop) == 0){
                Query q = toQuery(eleOnTop);
                this.operates.pop();
                this.querys.push(q);
              }else{
                Query q = toQuery(eleOnTop);
                this.operates.pop();
                this.querys.push(q);
              }
            }
           
            if(doPeek && this.operates.empty()){
              this.operates.push(e);
            }
          }
        }     
      }
     
      while(!this.operates.isEmpty()){
        Element eleOnTop = this.operates.pop();
        Query q = toQuery(eleOnTop);
        this.querys.push(q);     
      }   
    }
View Full Code Here

      if(this.querys.size() == 1){
        return this.querys.get(0);
      }
     
      Query q2 = this.querys.pop();
      Query q1 = this.querys.pop();
      if('&' == op.type){
        if(q1 != null){
          if(q1 instanceof BooleanQuery){
            BooleanClause[] clauses = ((BooleanQuery)q1).getClauses();
            if(clauses.length > 0
View Full Code Here

    System.out.println("***************")
 
  }
 
  public void testQueryParser(){
    Query query = null;
//      String[] fields = new String[]{"f1" , "f3" , "f5"};
//      query = IKQueryParser.parseMultiField(fields,  "title:评测");
      query = IKQueryParser.parse("t""和服装饰品");
    System.out.println(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

    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

  public void testSearch() {
    try {
      IndexSearcher searcher = new IndexSearcher(dir);
      QueryParser qp = new QueryParser(Version.LUCENE_29, "txt", analyzer);
      Query q = qp.parse("西伯利亚")//2008年底
      System.out.println(q);
      TopDocs tds = searcher.search(q, 10);
      System.out.println("======size:"+tds.totalHits+"========");
      for(ScoreDoc sd : tds.scoreDocs) {
        System.out.println(sd.score);
View Full Code Here

                }
            }

            for (String subIndex : localShards)
            {
                Query q = QueryParsing.parseQuery(cmd.query, schema);
                long total = writer.deleteDocuments(subIndex, q, false);
                commit(subIndex, true);
                logger.info("Deleted " + total + " Documents in " + subIndex);
            }
View Full Code Here

  }

  // Test that FieldScoreQuery returns docs in expected order.
  private void doTestRank (String field, FieldScoreQuery.Type tp) throws Exception {
    IndexSearcher s = new IndexSearcher(dir, true);
    Query q = new FieldScoreQuery(field,tp);
    log("test: "+q);
    QueryUtils.check(random, q,s);
    ScoreDoc[] h = s.search(q, null, 1000).scoreDocs;
    assertEquals("All docs should be matched!",N_DOCS,h.length);
    String prevID = "ID"+(N_DOCS+1); // greater than all ids of docs in this test
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.