Package org.apache.lucene.search

Examples of org.apache.lucene.search.Query


          String q = st.nextToken();
      String[] indexFields = searching.getIndexFields();
      for(int i=0;i<indexFields.length;i++){
        QueryParser qp = new QueryParser(indexFields[i], analyzer);
        try{
          Query subjectQuery = qp.parse(q);
          comboQuery.add(subjectQuery, BooleanClause.Occur.SHOULD);
          _query_count ++;
        }catch(Exception e){
          log.error("Add query parameter failed. key="+q, e);
        }
View Full Code Here


            // reuse the same analyzer; it's thread-safe;
            // also allows subclasses to control the analyzer used.
            Analyzer analyzer = access.writer.getAnalyzer();
            QueryParser parser = new QueryParser(Version.LUCENE_30,
                    LUCENE_FIELD_DATA, analyzer);
            Query query = parser.parse(text);
            // Lucene 3 insists on a hard limit and will not provide
            // a total hits value. Take at least 100 which is
            // an optimal limit for Lucene as any more
            // will trigger writing results to disk.
            int maxResults = (limit == 0 ? 100 : limit) + offset;
View Full Code Here

  public List<E> list(String search, String... fields) {
    return this.list(search, new StandardAnalyzer(), fields);
  }

  public List<E> list(String search, Analyzer analyzer, String... fields) {
    Query query = this.buildQuery(search, fields);
    if (query != null)
      return this.list(query);
    else
      return null;
  }
View Full Code Here

    return fQuery.getResultList();
  }

  public Page<E> page(Pagination pagination, String search,
      Analyzer analyzer, String... fields) {
    Query query = this.buildQuery(search, fields);

    if (query != null)
      return this.page(pagination, query);
    else
      return null;
View Full Code Here

  public Page<E> page(Pagination pagination, String search, String... fields) {
    return this.page(pagination, search, new StandardAnalyzer(), fields);
  }

  private Query buildQuery(String search, String... fields) {
    Query query = null;
    try {
      MultiFieldQueryParser parser = new MultiFieldQueryParser(fields,
          new StandardAnalyzer());
      if (search != null && !search.trim().equals("")) {
        StringBuffer cds = new StringBuffer();
View Full Code Here

    print(mTemplate);
  }

  private void initializeHighlighting() throws EngineException
  {
    Query query = null;

    mSearchBean = (Search.SearchBean)getNamedInputBean("SearchBean");
    if (mSearchBean != null &&
      mSearchBean.getKeyword() != null &&
      !mSearchBean.getKeyword().equals(""))
    {
      try
      {
        query = QueryParser.parse(mSearchBean.getKeyword(), "message", new StandardAnalyzer());
      }
      catch (org.apache.lucene.queryParser.ParseException e)
      {
        // just ignore it, nothing I can do
      }
    }

    if (query != null)
    {
      try
      {
        Collection   bots = BotsRunner.getRepInstance().getBots();
        Iterator   iter = bots.iterator();

        String readerDir = null;
        while (iter.hasNext())
        {
          Bot bot = (Bot)iter.next();

          if (bot.getName().equals(getInput("botname")))
          {
            StringBuffer key = new StringBuffer();
            key
              .append(Config.getRepInstance().getString("LUCENE_DIR"))
              .append(File.separator)
              .append(bot.getName())
              .append("-")
              .append(bot.getServer().getServerName())
              .append("-")
              .append(getInput("channelname").substring(1));

            readerDir = key.toString();
          }
        }

        if (readerDir != null)
        {
          IndexReader     reader = IndexReader.open(readerDir);
          SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span class=\"highlighted\">", "</span>");

          mHighlighter = new Highlighter(formatter, new QueryScorer(query.rewrite(reader)));
        }
        else
        {
          throw new IOException("Couldn't find the correct index directory for this bot, channel, and server combination");
        }
View Full Code Here

  public List<Song> search(String condition,String artistCityId) {
    try {
      BooleanQuery booleanQuery = new BooleanQuery();
      MultiFieldQueryParser parser = new MultiFieldQueryParser(
          new String[] { "name", "lyric" }, new StandardAnalyzer());
      Query query;
      query = parser.parse(condition);
      booleanQuery.add(query, BooleanClause.Occur.MUST);
      if(artistCityId != null){
        TermQuery tq = new TermQuery(new Term("artistCityId", artistCityId));
        booleanQuery.add(tq, BooleanClause.Occur.MUST);
View Full Code Here

        }
    }

    public Hits getOverview( NewsGroup group ) throws IOException, ParseException {
        IndexSearcher searcher = new IndexSearcher( articleOverviewDirectory );
        Query query = QueryParser.parse( group.getName(), "newsgroup", new StandardAnalyzer());
        Hits hits = searcher.search( query );
        return hits;
    }
View Full Code Here

           .buildQueryBuilder().forEntity(Product.class).get();
       
        //Hibernate Search fulltext query example:
       
        //query to match exact terms occurrence, using custom boosts:
        Query queryToFindExactTerms = queryBuilder.keyword()
           .onFields("title").boostedTo(4f)
           .andField("description").boostedTo(2f)
           .andField("actors.name").boostedTo(2f)
           .andField("categories.name").boostedTo(0.5f)
           .matching(textQuery)
           .createQuery();
       
        //Similar query, but using NGram matching instead of exact terms:
        Query queryToFindMathingNGrams = queryBuilder.keyword()
           .onFields("title:ngrams").boostedTo(2f)
           .andField("description:ngrams")
           .andField("actors.name:ngrams")
           .andField("categories.name:ngrams").boostedTo(0.2f)
           .matching(textQuery)
           .createQuery();
       
        //Combine them for best results, note exact uses an higher boost:
        Query fullTextQuery = queryBuilder.bool()
           .should(queryToFindMathingNGrams)
           .should(queryToFindExactTerms)
           .createQuery();
       
        log.info("Executing fulltext query {0}", fullTextQuery);
View Full Code Here

       
      } catch (ParseException e) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
      }
   
    Query query = rb.getQuery();
      SortSpec sortspec = rb.getSortSpec();
      Sort sort = null;
      if (sortspec!=null){
        sort = sortspec.getSort();
      }
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.