Package org.apache.lucene.search

Examples of org.apache.lucene.search.Query


   */
  public List<ItemResult> search(ChannelGroupIF channels,
                     String queryString, int maxResults)
    throws QueryParseException, IOException {

    Query query = null;
    try {
      logger.info("Searching for '" + queryString + "'.");
      query = QueryParser.parse(queryString,
                                ItemFieldConstants.TITLE_AND_DESC,
                                analyzer);
View Full Code Here


    Object key = Pool.createHashKeys(new Object[] {text, query, textAnalyzer, queryAnalyzer});
    Float score = (Float) entries.get(key); // hit/miss ratio is app specific
//    Float score = null;
    if (score == null) { // cache miss
      Object qkey = Pool.createHashKeys(new Object[] {query, queryAnalyzer});
      Query luceneQuery = (Query) entries.get(qkey); // typically good hit/miss ratio
//      Query luceneQuery = null;
      if (luceneQuery == null) { // cache miss
        luceneQuery = parse(query, queryAnalyzer);
        entries.put(qkey, luceneQuery);
      }
View Full Code Here

      indexes[i].addField(field, lines.get(i).getValue(), textAnalyzer);
    }
    doc = null;   // help gc
    lines = null; // help gc
   
    Query query = new QueryParser(field, queryAnalyzer).parse(queryExpr);
   
    float sum = 0;
    for (int run=0; run < runs; run++) {
      System.out.println("\nrun=" + run);
      long start = System.currentTimeMillis();
View Full Code Here

          Document doc = createDocument(text);
          System.out.println("\n*********** FILE=" + file);
         
          for (int q=0; q < queries.length; q++) {
            try {
              Query query = parseQuery(queries[q]);
             
              for (int run=0; run < runs; run++) {
                float score1 = 0.0f; float score2 = 0.0f;
                if (useMemIndex) score1 = query(createMemoryIndex(doc), query);
                if (useRAMIndex) score2 = query(createRAMIndex(doc), query);
View Full Code Here

        BooleanQuery includeQuery = new BooleanQuery();
        BooleanQuery excludeQuery = new BooleanQuery();

        for (String s : getNames()) {
            Query iq = buildIncludeQuery(s, search);
            if (iq != null) {
                log.debug("include query: " + iq.toString());
                includeQuery.add(iq, BooleanClause.Occur.SHOULD);
                Query eq = buildExcludeQuery(s, search);
                if (eq != null) {
                    log.debug("exclude query: " + eq.toString());
                    excludeQuery.add(eq, BooleanClause.Occur.SHOULD);
                }
            }
        }
View Full Code Here

    }

    public Query getQuery(PropertySearch search) {
        BooleanQuery query = new BooleanQuery();

        Query iq = buildIncludeQuery(getName(), search);
        if (iq != null) {
            log.debug("include query: " + iq.toString());
            query.add(iq, BooleanClause.Occur.MUST );
            Query eq= buildExcludeQuery(getName(), search);
            if (eq != null) {
                log.debug("exclude query: " + eq.toString());
                query.add(eq, BooleanClause.Occur.MUST_NOT);
            }
        }
       
        return query.getClauses().length > 0 ? query : null;
View Full Code Here

         searchPattern = null;
         return getLatestBlogEntries(100);
      }
      else
      {
         Query luceneQuery = getFullTextQuery();
         return entityManager.createFullTextQuery(luceneQuery, BlogEntry.class)
               .setMaxResults(100)
               .getResultList();
      }
   }
View Full Code Here

         .buildQueryBuilder()
         .forEntity(BlogEntry.class)
         .get();
     
      //A fulltext query using English Analyzer
      Query queryUsingEnglishStemmer = queryBuilder.keyword()
         .onFields("title:en").boostedTo(4f)
         .andField("body:en")
         .matching(searchPattern)
         .createQuery();
     
      //A fulltext query using ngrams
      Query queryUsingNGrams = queryBuilder.keyword()
         .onFields("title:ngrams").boostedTo(2f)
         .andField("body:ngrams").boostedTo(0.4f)
         .matching(searchPattern)
         .createQuery();
     
      //Combine them for best results:
      Query fullTextQuery = queryBuilder.bool()
         .should(queryUsingEnglishStemmer)
         .should(queryUsingNGrams)
         .createQuery();
     
      return fullTextQuery;
View Full Code Here

      }
      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.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));
      Hits hits = searcher.search(query);
     
      BoldFormatter formatter = new BoldFormatter();
      Highlighter highlighter =new Highlighter(formatter,new QueryScorer(query));
      highlighter.setTextFragmenter(new SimpleFragmenter(50));
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.