Package org.apache.lucene.search

Examples of org.apache.lucene.search.BooleanQuery


   * @param copy If <code>true</code>, only consider copied News.
   * @return a List of {@link NewsReference} matching the given search.
   */
  public List<NewsReference> searchNewsByLink(URI link, boolean copy) {
    Assert.isNotNull(link, "link"); //$NON-NLS-1$
    BooleanQuery query = createNewsByLinkBooleanQuery(link, copy);
    return simpleSearch(query);
  }
View Full Code Here


    BooleanQuery query = createNewsByLinkBooleanQuery(link, copy);
    return simpleSearch(query);
  }

  private BooleanQuery createNewsByLinkBooleanQuery(URI link, boolean copy) {
    BooleanQuery query = new BooleanQuery(true);
    query.add(new TermQuery(new Term(String.valueOf(INews.LINK), link.toString().toLowerCase())), Occur.MUST);
    query.add(createIsCopyTermQuery(copy));
    return query;
  }
View Full Code Here

   * @param copy If <code>true</code>, only consider copied News.
   * @return a List of {@link NewsReference} matching the given search.
   */
  public List<NewsReference> searchNewsByGuid(IGuid guid, boolean copy) {
    Assert.isNotNull(guid, "guid"); //$NON-NLS-1$
    BooleanQuery query = createGuidQuery(guid, copy);
    return simpleSearch(query);
  }
View Full Code Here

    BooleanQuery query = createGuidQuery(guid, copy);
    return simpleSearch(query);
  }

  private BooleanQuery createGuidQuery(IGuid guid, boolean copy) {
    BooleanQuery query = new BooleanQuery(true);
    query.add(new TermQuery(new Term(String.valueOf(INews.GUID), guid.getValue().toLowerCase())), Occur.MUST);
    query.add(createIsCopyTermQuery(copy));
    return query;
  }
View Full Code Here

        }
        return name;
    }

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

        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);
                }
            }
        }

        if (includeQuery.getClauses().length > 0) query.add(includeQuery, BooleanClause.Occur.MUST);
        if (excludeQuery.getClauses().length > 0) query.add(excludeQuery, BooleanClause.Occur.MUST_NOT);
        return query.getClauses().length > 0 ? query : null;
    }
View Full Code Here

    public String toString() {
        return getName();
    }

    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

      DebugFile.incIdent();
    }

    MailRecord[] aRetArr;

  BooleanQuery oFld = new BooleanQuery();
  for (int f=0; f<aFolderName.length; f++)
    oFld.add(new TermQuery(new Term("container",aFolderName[f])),BooleanClause.Occur.SHOULD);

  BooleanQuery oQry = new BooleanQuery();

  oQry.add(new TermQuery(new Term("workarea",sWorkArea)),BooleanClause.Occur.MUST);
    oQry.add(oFld, BooleanClause.Occur.MUST);

    if (null!=sSender)
      oQry.add(new TermQuery(new Term("author",Gadgets.ASCIIEncode(sSender))),BooleanClause.Occur.MUST);
    
    if (null!=sRecipient)
      oQry.add(new TermQuery(new Term("recipients",sRecipient)),BooleanClause.Occur.MUST);
     
    if (null!=sSubject)
      oQry.add(new TermQuery(new Term("title",Gadgets.ASCIIEncode(sSubject))),BooleanClause.Occur.MUST);
  
    if (dtFromDate!=null && dtToDate!=null)
    oQry.add(new RangeQuery(new Term("created",DateTools.dateToString(dtFromDate, DateTools.Resolution.DAY)),
                  new Term("created",DateTools.dateToString(dtToDate, DateTools.Resolution.DAY)), true), BooleanClause.Occur.MUST);   
    else if (dtFromDate!=null)
    oQry.add(new RangeQuery(new Term("created",DateTools.dateToString(dtFromDate, DateTools.Resolution.DAY)),
                  new Term("created",DateTools.dateToString(new Date(299,11,31), DateTools.Resolution.DAY)), true), BooleanClause.Occur.MUST);   
    else if (dtToDate!=null)
    oQry.add(new RangeQuery(new Term("created",DateTools.dateToString(new Date(79,11,31), DateTools.Resolution.DAY)),
                  new Term("created",DateTools.dateToString(dtToDate, DateTools.Resolution.DAY)), true), BooleanClause.Occur.MUST);

    if (null!=sText)
      oQry.add(new TermQuery(new Term("text",sText)),BooleanClause.Occur.SHOULD);

  String sSegments = Gadgets.chomp(sLuceneIndexPath,File.separator)+"k_mime_msgs"+File.separator+sWorkArea; 
    if (DebugFile.trace) DebugFile.writeln("new IndexSearcher("+sSegments+")");
    IndexSearcher oSearch = new IndexSearcher(sSegments);

    if (iLimit>0) {
      if (DebugFile.trace) DebugFile.writeln("IndexSearcher.search("+oQry.toString()+", null, "+String.valueOf(iLimit)+")");
      TopDocs oTopSet = oSearch.search(oQry, null, iLimit);
      if (oTopSet.scoreDocs!=null) {
        ScoreDoc[] oTopDoc = oTopSet.scoreDocs;
        int iDocCount = oTopDoc.length;
        if (DebugFile.trace) DebugFile.writeln("doc count is "+String.valueOf(iDocCount));
        aRetArr = new MailRecord[iDocCount];
        for (int d=0; d<iDocCount; d++) {
          Document oDoc = oSearch.doc(oTopDoc[d].doc);
          String[] aAbstract = Gadgets.split(oSearch.doc(oTopDoc[d].doc).get("abstract"), 'ยจ');
          aRetArr[d] = new MailRecord(aAbstract[0], aAbstract[1], aAbstract[2],
                                      aAbstract[3], aAbstract[4], aAbstract[5],
                                      oDoc.get("container"));
        } // next
      } else {
        aRetArr = null;
      }
    } else {
      if (DebugFile.trace) DebugFile.writeln("IndexSearcher.search("+oQry.toString()+")");
      Hits oHitSet = oSearch.search(oQry);
      int iHitCount = oHitSet.length();
      if (DebugFile.trace) DebugFile.writeln("hit count is "+String.valueOf(iHitCount));
      if (iHitCount>0) {
        aRetArr = new MailRecord[iHitCount];
View Full Code Here

    if(queries.size() == 0){
      return null;
    }else if(queries.size() == 1){
      return queries.get(0);
    }else{
      BooleanQuery mustQueries = new BooleanQuery();
      for(Query q : queries){
        mustQueries.add(q, Occur.MUST);
      }
      return mustQueries;
    }     
  }
View Full Code Here

   */
  public static Query parseMultiField(String[] fields , String query) throws IOException{
    if(fields == null){
      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);
        }
      }     
    }   
    return resultQuery;
  }
View Full Code Here

   
    if (flags.length != fields.length){
          throw new IllegalArgumentException("flags.length != fields.length");
    }   
   
    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]);
        }
      }     
    }   
    return resultQuery;
  }
View Full Code Here

TOP

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

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.