Package org.apache.lucene.search

Examples of org.apache.lucene.search.BooleanQuery


        return null;
     
      IndexSearcher searcher = new IndexSearcher(path.toString());
     
        //���������ؼ���
        BooleanQuery comboQuery = new BooleanQuery();
        int _query_count = 0;
        StringTokenizer st = new StringTokenizer(params.getSearchKey());
        while(st.hasMoreElements()){
          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


    //it also probably minimise the memory footprint
    if ( classesAndSubclasses == null ) {
      return luceneQuery;
    }
    else {
      BooleanQuery classFilter = new BooleanQuery();
      //annihilate the scoring impact of DocumentBuilder.CLASS_FIELDNAME
      classFilter.setBoost( 0 );
      for (Class clazz : classesAndSubclasses) {
        Term t = new Term( DocumentBuilder.CLASS_FIELDNAME, clazz.getName() );
        TermQuery termQuery = new TermQuery( t );
        classFilter.add( termQuery, BooleanClause.Occur.SHOULD );
      }
      BooleanQuery filteredQuery = new BooleanQuery();
      filteredQuery.add( luceneQuery, BooleanClause.Occur.MUST );
      filteredQuery.add( classFilter, BooleanClause.Occur.MUST );
      return filteredQuery;
    }
  }
View Full Code Here

  }

  @Transactional(type = TransactionalType.READOLNY)
  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);
      }
      org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(
          booleanQuery, Song.class);
      return hibQuery.list();
     
View Full Code Here

    addDocumentToQueue(getIndexName(botname, servername, channelname), doc);
  }

  public BooleanQuery getSearchQuery(Search.SearchBean bean)
  {
     BooleanQuery query = new BooleanQuery();

    if (bean.getKeyword() != null &&
      !bean.getKeyword().equals(""))
    {
      try
      {
        mKeywordQuery = QueryParser.parse(bean.getKeyword(), "message", getAnalyzer());
       
        query.add(mKeywordQuery, true, false);
      }
      catch (org.apache.lucene.queryParser.ParseException e)
      {
        bean.addValidationError(new ValidationError.INVALID("keyword"));
      }
    }

    if (bean.getDate() != null &&
      !bean.getDate().equals(""))
    {
      try
      {
        Date parsed = Search.INPUT_DATE_FORMAT_SHORT.parse(bean.getDate());

        Calendar cal = Calendar.getInstance();
        cal.setTimeZone(TimeZone.getTimeZone(DroneConfig.getTimezone()));
        cal.setTime(parsed);

        Term begin = new Term("moment", DateField.dateToString(cal.getTime()));

        cal.set(Calendar.HOUR, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        Term end = new Term("moment", DateField.dateToString(cal.getTime()));

        query.add(new RangeQuery(begin, end, true), true, false);
      }
      catch (Exception e)
      {
        bean.addValidationError(new ValidationError.WRONGFORMAT("date"));
      }
    }

    boolean beginDatePresent = (bean.getBeginDate() != null && !bean.getBeginDate().equals(""));
    boolean endDatePresent = (bean.getEndDate() != null && !bean.getEndDate().equals(""));

    if (beginDatePresent && endDatePresent)
    {
      String beginDateFormatted = null;
      String endDateFormatted = null;
      try
      {
        Date beginDateParsed = Search.INPUT_DATE_FORMAT_SHORT.parse(bean.getBeginDate());
        Date endDateParsed = Search.INPUT_DATE_FORMAT_SHORT.parse(bean.getEndDate());

        Calendar cal = Calendar.getInstance();
        cal.setTime(endDateParsed);

        cal.set(Calendar.HOUR, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);

        beginDateFormatted = DateField.dateToString(beginDateParsed);
        endDateFormatted = DateField.dateToString(cal.getTime());
      }
      catch (ParseException e)
      {
        bean.addValidationError(new ValidationError.WRONGFORMAT("beginDate"));
        bean.addValidationError(new ValidationError.WRONGFORMAT("endDate"));
      }

      if (bean.getValidationErrors().size() == 0)
      {
        Term begin = new Term("moment", beginDateFormatted);
        Term end = new Term("moment", endDateFormatted);

        query.add(new RangeQuery(begin, end, true), true, false);
      }
    }
    else if (!beginDatePresent && !endDatePresent)
    {
      // noop; means they didn't try a date range
    }
    else
    {
      bean.addValidationError(new ValidationError.INCOMPLETE("dateRange"));
    }

    if (bean.getUser() != null &&
      !bean.getUser().equals(""))
    {
      try
      {
        query.add(QueryParser.parse(bean.getUser(), "nickname", getAnalyzer()), true, false);
      }
      catch (org.apache.lucene.queryParser.ParseException e)
      {
        bean.addValidationError(new ValidationError.INVALID("user"));
      }
    }

    if (bean.getChannel() != null &&
      !bean.getChannel().equals("") &&
         !bean.getChannel().equals("All"))
    {
      try
      {
        int pos = bean.getChannel().indexOf("#");
       
        String botname = bean.getChannel().substring(0, pos - 3);
        String channel = bean.getChannel().substring(pos + 1);
       
        query.add(QueryParser.parse(channel, "channel", getAnalyzer()), true, false);
        query.add(QueryParser.parse(botname, "botname", getAnalyzer()), true, false);
      }
      catch (org.apache.lucene.queryParser.ParseException e)
      {
        bean.addValidationError(new ValidationError.INVALID("channel"));
      }
View Full Code Here

    map2.put("circle", 3.0f);
    map2.put("square", 2.0f);
    FacetTermQuery shapeQ = new FacetTermQuery(sel2,map2);
    shapeQ.setBoost(3.0f);
   
    BooleanQuery bq = new BooleanQuery();
    bq.add(shapeQ,Occur.SHOULD);
    bq.add(colorQ,Occur.SHOULD);
   
    BrowseRequest br = new BrowseRequest();
    br.setSort(new SortField[]{SortField.FIELD_SCORE});
    br.setQuery(bq);
    br.setOffset(0);
View Full Code Here

      br.setOffset(0);
      br.setCount(10);
     
     
      BooleanQuery bq = new BooleanQuery(true);
      bq.add(colorQ, Occur.SHOULD);
      bq.add(tagQ, Occur.SHOULD);
     
      br.setQuery(bq);
      doTest(br, 6, null, new String[]{"7","1","3","2","4","5"});
     
     
View Full Code Here

  public void testPrefixQuery() throws ParseException {
    doConvert(new PrefixQuery(new Term("tags", "h")));
  }

  public void testBooleanQuery() throws ParseException {
    BooleanQuery bq = new BooleanQuery();
    Query q1 = new TermQuery(new Term("tags", "h*"));
    BooleanClause bc = new BooleanClause(q1, BooleanClause.Occur.MUST);
    bq.add(bc);
    doConvert(bq);
  }
View Full Code Here

      req.setFacetSpec("geo_region", spec);
//      req.setFacetSpec("industry", spec);
      String qstr = words[nextInt()];
//      qstr = "project manager";
      String[] terms = qstr.split(" ");
      BooleanQuery q = new BooleanQuery();
    for(String s : terms)
    {
      q.add( new TermQuery(new Term("b",s)), Occur.MUST);
    }
//      q.add(new MatchAllDocsQuery(), Occur.MUST);
      req.setQuery(q);//new TermQuery(new Term("b",qstr)));
      BrowseSelection sel = new BrowseSelection("ccid");
      sel.addValue("0000001384");
View Full Code Here

      DebugFile.incIdent();
    }

    BugRecord[] aRetArr;

  BooleanQuery oQry = new BooleanQuery();

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

    if (null!=sProjectGUID)
    if (sProjectGUID.length()>0)
      oQry.add(new TermQuery(new Term("container",sProjectGUID)),BooleanClause.Occur.MUST);

    if (null!=sWrittenBy)
      if (sWrittenBy.length()>0)
      oQry.add(new TermQuery(new Term("writer",sWrittenBy)),BooleanClause.Occur.MUST);

    if (null!=sReportedBy)
      if (sReportedBy.length()>0)
      oQry.add(new TermQuery(new Term("author",sReportedBy)),BooleanClause.Occur.MUST);

    if (null!=sTitle)
      if (sTitle.length()>0)
      oQry.add(new TermQuery(new Term("title",sTitle)),BooleanClause.Occur.MUST);

    if (null!=sType)
      if (sType.length()>0)
      oQry.add(new TermQuery(new Term("type",sType)),BooleanClause.Occur.MUST);

    if (null!=sStatus)
      if (sStatus.length()>0)
      oQry.add(new TermQuery(new Term("status",sStatus)),BooleanClause.Occur.MUST);

    if (null!=sPriority)
      if (sPriority.length()>0)
      oQry.add(new TermQuery(new Term("priority",sPriority)),BooleanClause.Occur.MUST);

    if (null!=sSeverity)
      if (sSeverity.length()>0)
      oQry.add(new TermQuery(new Term("severity",sSeverity)),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)
      if (sText.length()>0)
      oQry.add(new TermQuery(new Term("text",sText)),BooleanClause.Occur.SHOULD);

    if (null!=sComments)
      if (sComments.length()>0)
      oQry.add(new TermQuery(new Term("comments",sComments)),BooleanClause.Occur.SHOULD);

  String sSegments = Gadgets.chomp(sLuceneIndexPath,File.separator)+"k_bugs"+File.separator+sWorkArea; 
    if (DebugFile.trace) DebugFile.writeln("new IndexSearcher("+sSegments+")");
    IndexSearcher oSearch = new IndexSearcher(sSegments);
   
View Full Code Here

      DebugFile.writeln("Begin ContactSearcher.search("+oProps.getProperty("luceneindex")+","+
                        sWorkArea+","+String.valueOf(20)+")");
      DebugFile.incIdent();
    }

  BooleanQuery oQry = new BooleanQuery();

  oQry.add(new TermQuery(new Term("workarea",sWorkArea)),BooleanClause.Occur.MUST);
 
  for(int i=0; i<values.length;i++){
    if(obligatorio[i]){
      oQry.add(new TermQuery(new Term("value",values[i])),BooleanClause.Occur.MUST);
    }else{
      oQry.add(new TermQuery(new Term("value",values[i])),BooleanClause.Occur.SHOULD);
    }
  }

  String sSegments = Gadgets.chomp(oProps.getProperty("luceneindex"),File.separator)+"k_contacts"+File.separator+sWorkArea; 
    if (DebugFile.trace) DebugFile.writeln("new IndexSearcher("+sSegments+")");
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.