Package org.apache.lucene.queryParser

Examples of org.apache.lucene.queryParser.QueryParser


        boostPerField.put("description", 2f);
        boostPerField.put("actors.name", 2f);
        boostPerField.put("categories.name", 0.5f);

        String[] productFields = {"title", "description", "actors.name", "categories.name"};
        QueryParser parser = new MultiFieldQueryParser(productFields, new StandardAnalyzer(), boostPerField);
        parser.setAllowLeadingWildcard(true);
        org.apache.lucene.search.Query luceneQuery;
        luceneQuery = parser.parse(searchQuery);
        return ( (FullTextEntityManager) em ).createFullTextQuery(luceneQuery, Product.class);
    }
View Full Code Here


          checkIsIndexUpToDate();
        }     
      }
      log.info("queryString=" + queryString);
     
      QueryParser queryParser = new MultiFieldQueryParser(Version.LUCENE_CURRENT, fields, analyzer);
      queryParser.setLowercaseExpandedTerms(false);//some add. fields are not tokenized and not lowered case
      Query query = queryParser.parse(queryString);
      try {
        query = searcher.rewrite(query);
      } catch (Exception ex) {
        throw new QueryException("Rewrite-Exception query because too many clauses. Query=" + query);
      }
View Full Code Here

      writer.optimize();
      writer.close();
     
      IndexReader reader = IndexReader.open(ramDir);
      String queryString = QUERY;
      QueryParser parser=new QueryParser(FIELD_NAME, /*new StandardAnalyzer()/*/XFactory.getWriterAnalyzer());
      Query query = parser.parse(queryString);
      System.out.println(query);
      Searcher searcher = new IndexSearcher(ramDir);
      query = query.rewrite(reader);
      System.out.println(query);
      System.out.println("Searching for: " + query.toString(FIELD_NAME));
View Full Code Here

    writer.optimize();
    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);
View Full Code Here

    writer.optimize();
    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);   
View Full Code Here

     */
    private Query luceneQueryParse(String fieldName , String keyword){
      //截取头部^尾部$
      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

    writer.optimize();
    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);   
View Full Code Here

    writer.optimize();
    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);
View Full Code Here

    writer.optimize();
    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);
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

TOP

Related Classes of org.apache.lucene.queryParser.QueryParser

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.