Package org.apache.lucene.search

Examples of org.apache.lucene.search.Searcher


    super(name);
  }

  private static int countHits(ZoieSystem<IndexReader,String, DefaultZoieVersion> idxSystem, Query q) throws IOException
  {
    Searcher searcher = null;
    MultiReader reader= null;
    List<ZoieIndexReader<IndexReader>> readers = null;
    try
    {
      readers=idxSystem.getIndexReaders();
      reader = new MultiReader(readers.toArray(new IndexReader[readers.size()]),false);

      searcher=new IndexSearcher(reader);

      TopDocs hits = searcher.search(q,10);

      return hits.totalHits;
    }
    finally
    {
      try{
        if (searcher != null){
          searcher.close();
          searcher = null;
          reader.close();
          reader = null;
        }
      }
View Full Code Here


    memoryProvider.addEvents(list);

    memoryProvider.flush();
    idxSystem.syncWthVersion(10000, zvt2);
    List<ZoieIndexReader<IndexReader>> readers = null;
    Searcher searcher =null;
    MultiReader reader = null;
    try
    {    
      readers=idxSystem.getIndexReaders();
      reader = new MultiReader(readers.toArray(new IndexReader[readers.size()]),false);
      for(int i=0; i<readers.size(); i++)
      {
        IndexReader ir = readers.get(i);
        //Map<String, String> commitData = reader.getCommitUserData(ir.directory()); // = new HashMap<String,String>();
        //System.out.println("ZoieTest: directory: " + ir.directory());
        //System.out.println("ZoieTest: commitData(ZoieVersion): " + commitData); 
      }
      //Map<String, String> commitData = reader.getCommitUserData(reader.directory());// = new HashMap<String,String>();
//      for(int i=0; i<readers.size(); i++)
//      {
//        IndexReader ir = readers.get(i);
//        Map<String, String> commitData = IndexReader.getCommitUserData(ir.directory()); // = new HashMap<String,String>();
//        System.out.println("i:" + i + "ZoieTest: directory: " + ir.directory());
//        System.out.println("i:" + i + "ZoieTest: commitData(ZoieVersion): " + commitData); 
//      }
    
      //Map<String, String> commitData = IndexReader.getCommitUserData(reader.directory());// = new HashMap<String,String>();
      //System.out.println("ZoieTest:commitData" + commitData); 
    
      //commitData = reader.getCommitUserData();     
     
//int x = reader.maxDoc();
//for(int y = 0; y<x; y++)
//{
//  Document d = reader.document(y);
//  System.out.println(d.toString()); 
//}

//TermEnum terms = reader.terms();
//while(terms.next())
//{
//  System.out.println(terms.term().text());
//  TermDocs td = reader.termDocs(terms.term());
//  while(td.next())
//  {
//    System.out.println(td.doc());
//  }
//}

//terms = reader.terms();
//while(terms.next())
//{
//  System.out.println("term:" + terms.term().text());
//  TermPositions tp = reader.termPositions(terms.term());
// 
//  while(tp.next())
//  {
//    System.out.println("docID: " + tp.doc() + "freq: " + tp.freq());
//    System.out.println("positions");
//    for(int i=0; i<tp.freq();i++)
//    {
//      System.out.println(tp.nextPosition());
//    }
//  }
//}
      searcher=new IndexSearcher(reader);

      TopDocs hits=searcher.search(new TermQuery(new Term("contents","hao,yan")),10);

      assertEquals(1,hits.totalHits);
      //assertEquals(String.valueOf((long)((long)Integer.MAX_VALUE*2L)),searcher.doc(hits.scoreDocs[0].doc).get("id"));
     assertEquals(String.valueOf((long)((long)Integer.MAX_VALUE*2L+1L)),searcher.doc(hits.scoreDocs[0].doc).get("id"));

      hits=searcher.search(new TermQuery(new Term("contents","hao")),10);
      assertEquals(1,hits.totalHits);
      //assertEquals(String.valueOf((long)((long)Integer.MAX_VALUE*2L)),searcher.doc(hits.scoreDocs[0].doc).get("id"));
      System.out.println("hao: searching is successful");
    }
    finally
    {
      try{
        if (searcher != null){
          searcher.close();
          searcher = null;
          reader.close();
          reader = null;
        }
      }
View Full Code Here

      int[] results = new int[repeat];
      int[] expected = new int[repeat];
      Arrays.fill(expected, count);

      // should be consumed by the idxing system
      Searcher searcher=null;
      MultiReader reader= null;
      List<ZoieIndexReader<IndexReader>> readers = null;
      for (int i=0;i<repeat;++i)
      {
        try
        {
          readers=idxSystem.getIndexReaders();
          reader=new MultiReader(readers.toArray(new IndexReader[readers.size()]),false);

//          for(int j=0; j<readers.size(); j++)
//          {
//            IndexReader ir = readers.get(j);
//            Map<String, String> commitData = IndexReader.getCommitUserData(ir.directory()); // = new HashMap<String,String>();
//            System.out.println("j:" + j + "ZoieTest: directory: " + ir.directory());
//            System.out.println("j:" + j + "ZoieTest: commitData(ZoieVersion): " + commitData); 
//          }
         
          searcher=new IndexSearcher(reader);

          TopDocs hits=searcher.search(q,10);
          results[idx++] = hits.totalHits;

        }
        finally
        {
          try{
            if (searcher != null){
              searcher.close();
              searcher = null;
              reader.close();
              reader = null;
            }
          }
View Full Code Here

          }

          int expected = TestData.testdata.length;
          while(!stop)
          {
            Searcher searcher = null;
            List<ZoieIndexReader<IndexReader>> readers = null;
            MultiReader reader=null;
            try
            {
              readers=idxSystem.getIndexReaders();
              reader=new MultiReader(readers.toArray(new IndexReader[readers.size()]),false);

              searcher=new IndexSearcher(reader);

              TopDocs hits = searcher.search(q,10);
              int count = hits.totalHits;

              if (count != expected)
              {
                mismatch = true;
                message = "hit count: " + count +" / expected: "+expected;
                stop = true;
                StringBuffer sb = new StringBuffer();
                sb.append(message + "\n");
                sb.append("each\n");
                sb.append(groupDump(readers, q));
                sb.append("main\n");
                sb.append(dump(reader, hits));
                System.out.println(sb.toString());
                log.info(sb.toString());
              }
              Thread.sleep(20);
            }
            catch(Exception ex)
            {
              ex.printStackTrace();
              exception = ex;
              stop = true;
            }
            finally
            {
              try{
                if (searcher != null){
                  searcher.close();
                  reader.close();
                  reader = null;
                  searcher = null;
                }
              }
              catch(IOException ioe){
                log.error(ioe.getMessage(),ioe);
              }
              finally{
                idxSystem.returnIndexReaders(readers);
              }
            }
          }
        }
        private String groupDump(List<ZoieIndexReader<IndexReader>> readers, Query q) throws IOException
        {
          StringBuffer sb = new StringBuffer();
          for(ZoieIndexReader<IndexReader> reader : readers)
          {
            sb.append(reader).append("\n");
            Searcher searcher = new IndexSearcher(reader);
            TopDocs hits = searcher.search(q, 20);
            sb.append(dump(reader, hits));
            searcher.close();
            searcher = null;
          }
          return sb.toString();
        }
View Full Code Here

    
     
      QueryParser parser = new QueryParser(Version.LUCENE_CURRENT,"contents",idxSystem.getAnalyzer());
      Query q;
      Searcher searcher = null;
      List<ZoieIndexReader<IndexReader>> readers = null;

      TopDocs hits;

      q = parser.parse("zoie");
      readers=idxSystem.getIndexReaders();
     
      for(int i=0; i<readers.size(); i++)
      {
        IndexReader ir = readers.get(i);
        Map<String, String> commitData = IndexReader.getCommitUserData(ir.directory()); // = new HashMap<String,String>();
        System.out.println("i:" + i + "ZoieTest: directory: " + ir.directory());
        System.out.println("i:" + i + "ZoieTest: commitData(ZoieVersion): " + commitData)
      }
     
      if(2>1) return;
     
      MultiReader reader=new MultiReader(readers.toArray(new IndexReader[readers.size()]),false);

      searcher=new IndexSearcher(reader);
      hits = searcher.search(q,10);
      int expected = TestData.testdata.length;
      assertEquals("before update: zoie count mismatch[hit count: " + hits.totalHits +" / expected: "+TestData.testdata.length +"]", count, hits.totalHits);
      q = parser.parse("zoie2");

      searcher.close();
      reader.close();
      idxSystem.returnIndexReaders(readers);

      readers=idxSystem.getIndexReaders();
      reader=new MultiReader(readers.toArray(new IndexReader[readers.size()]),false);

      searcher=new IndexSearcher(reader);
      hits = searcher.search(q,10);
      assertEquals("before update: zoie2 count mismatch[hit count: " + hits.totalHits +" / expected: "+ 0 +"]", 0, hits.totalHits);
      searcher.close();
      reader.close();
      idxSystem.returnIndexReaders(readers);

      list = new ArrayList<DataEvent<String,DefaultZoieVersion>>(TestData.testdata2.length);
      for(int i = 0; i < TestData.testdata2.length; i++)
      {
        version = count + i;
        zvt = new DefaultZoieVersion();
        zvt.setVersionId(version);
        list.add(new DataEvent<String,DefaultZoieVersion>(TestData.testdata2[i],zvt));
      }
      memoryProvider.addEvents(list);
      idxSystem.syncWthVersion(10000, zvt);

      q = parser.parse("zoie");
      readers=idxSystem.getIndexReaders();
      reader=new MultiReader(readers.toArray(new IndexReader[readers.size()]),false);

      searcher=new IndexSearcher(reader);
      hits = searcher.search(q,10);
      expected = 0;
      assertEquals("after update: zoie count mismatch[hit count: " + hits.totalHits +" / expected: "+ 0 +"]", 0,  hits.totalHits);
      searcher.close();
      reader.close();
      idxSystem.returnIndexReaders(readers);

      q = parser.parse("zoie2");

      readers=idxSystem.getIndexReaders();
      reader=new MultiReader(readers.toArray(new IndexReader[readers.size()]),false);

      searcher=new IndexSearcher(reader);

      hits = searcher.search(q,10);
      expected = TestData.testdata2.length;
      assertEquals("after update: zoie2 count mismatch[hit count: " + hits.totalHits +" / expected: "+ expected +"]", expected, hits.totalHits);
      searcher.close();
      reader.close();
      idxSystem.returnIndexReaders(readers);
    }
    finally
    {
View Full Code Here

    SearchResult result=new SearchResult();
   
    List<R> readers=null;

    MultiReader multiReader=null;
    Searcher searcher = null;
    try
    {
      Query q=null;
      if (queryString == null || queryString.length() ==0)
      {
        q = new MatchAllDocsQuery();
      }
      else
      {
        q = qparser.parse(queryString);
      }
      readers=_idxReaderFactory.getIndexReaders();
      multiReader=new MultiReader(readers.toArray(new IndexReader[readers.size()]), false);
      searcher=new IndexSearcher(multiReader);
     
      long start=System.currentTimeMillis();
      TopDocs docs=searcher.search(q, null, 10);
      long end=System.currentTimeMillis();
     
      result.setTime(end-start);
      result.setTotalDocs(multiReader.numDocs());
      result.setTotalHits(docs.totalHits);
     

      ScoreDoc[] scoreDocs=docs.scoreDocs;
      ArrayList<SearchHit> hitList=new ArrayList<SearchHit>(scoreDocs.length);
      for (ScoreDoc scoreDoc : scoreDocs)
      {
        SearchHit hit=new SearchHit();
        hit.setScore(scoreDoc.score);
        int docid=scoreDoc.doc;
       
        Document doc=multiReader.document(docid);
        String content=doc.get("content");
       
        Scorer qs=new QueryScorer(q);
       
        SimpleHTMLFormatter formatter=new SimpleHTMLFormatter("<span class=\"hl\">","</span>");
        Highlighter hl=new Highlighter(formatter,qs);
        String[] fragments=hl.getBestFragments(analyzer, "content",content, 1);
       
        Map<String,String[]> fields=convert(doc);
        fields.put("fragment",fragments);
        hit.setFields(fields);
        hitList.add(hit);
      }
     
      result.setHits(hitList.toArray(new SearchHit[hitList.size()]));
      return result;
    }
    catch(Exception e)
    {
      log.error(e.getMessage(),e);
      throw new RuntimeException(e.getMessage(),e);
    }
    finally
    {
      try{
        if (searcher!=null)
        {
        try {
          searcher.close();
        } catch (IOException e) {
          log.error(e.getMessage(),e);
        }
        }
      }
View Full Code Here

  QueryParser qparser=new QueryParser(Version.LUCENE_CURRENT,"content",analyzer);
 
  SearchResult result=new SearchResult();
 
  List<R> readers=null;
  Searcher searcher = null;
  MultiReader multiReader=null;
  try
  {
    Query q=null;
    if (queryString == null || queryString.length() ==0)
    {
      q = new MatchAllDocsQuery();
    }
    else
    {
      q = qparser.parse(queryString);
    }
    readers=_idxReaderFactory.getIndexReaders();
    multiReader=new MultiReader(readers.toArray(new IndexReader[readers.size()]));
    searcher=new IndexSearcher(multiReader);
    TopDocs hits = searcher.search(q,10);
    result.setTotalDocs(multiReader.numDocs());
    result.setTotalHits(hits.totalHits);
    long end = System.nanoTime();
    long latency = (end-start)/NANOS_IN_MILLI;
    result.setTime(latency);
   
    int count = _numSearches.get();
    int index = count%SAMPLE_SIZE;
   
    _sum+=latency;
   
    if (count>SAMPLE_SIZE){
      _sum-=_latencies[index];
    }
//      countQuery((end / 1000 * NANOS_IN_MILLI));
//      now = end - now;
//      _latencies.add( (int)(now / NANOS_IN_MILLI));
//      _numHits.add(hits.totalHits);
    _latencies[index]=(int)latency;
    _numHits[index]=hits.totalHits;
   
    log.info("search=[query=" + req.getQuery() + "]" + ", searchResult=[numSearchResults=" + result.getTotalHits() + ";numTotalDocs=" + result.getTotalDocs() + "]" + "in " + result.getTime() + "ms");
      _numSearches.incrementAndGet();
      return result;
  }
  catch(Exception e)
  {
    log.error(e.getMessage(),e);
    throw new ZoieException(e.getMessage(),e);
  }
  finally
  {
    try{
      if (searcher!=null){
        try {
              searcher.close();
         } catch (IOException e) {
        log.error(e.getMessage(),e);
      }
      }
    }
View Full Code Here

                        StringBuffer tempBuf = new StringBuffer();
                        if (currentIndex.getShouldBeSearched()) {
                            String findText = "";

                            // create searcher
                            Searcher searcher = new IndexSearcher(currentIndex.getIndexPath());
                            if ((searchText.indexOf("(") != -1) || (searchText.indexOf("[") != -1)) {
                                findText = searchText;
                            }
                            else {
                              // add body and title, or single field to query
                              if (selectedFields == 0) {
                                    findText = "+(" + Index.FIELD_BODY + ":(" + searchText + ") OR " +
                                        Index.FIELD_TITLE + ":(" + searchText + "))";
                                }
                                else {
                                    // TODO dont use sField directly, because it is translated in other languages
                                      findText = "+" + sField + ":(" + searchText + ")";
                                }

                              // add author to query
                              if (useAuthor.isSelected()) {
                                    findText += " +" + Index.FIELD_AUTHOR + ":(" + authorField.getText() + ")";
                                }

                              // add filetype to query
                              if (useType.isSelected()) {
                                    findText += " +" + Index.FIELD_TYPE + ":(" + fileTypesToGet[fileType.getSelectedIndex()] + ")";
                                }
                            }
                            logger.debug("doSearch() query string '" + findText + "'");
                            setStatus(dsSrchStr + ": " + findText + "...");

                            // create query
                            QueryParser queryParser = new QueryParser(Index.FIELD_BODY, new StandardAnalyzer());
                            Query query = queryParser.parse(findText);

                            // check for date filter and search in index
                            Hits hits;
                            if (useDate.isSelected()) {
                                String dateFrom = DateTimeUtils.getDateStringForIndex(DateTimeUtils.getDateFromString(fromField.getText()));
                                String dateTo = DateTimeUtils.getDateStringForIndex(DateTimeUtils.getDateFromString(toField.getText()));
                                RangeFilter rangeFilter = new RangeFilter(Index.FIELD_MODDATE, dateFrom, dateTo, true, true);
                                if (logger.isDebugEnabled()) {
                                    logger.debug("doSearch() search with date range '" + rangeFilter + "'");
                                }

                                hits = searcher.search(query, rangeFilter);
                            }
                            else {
                                if (logger.isDebugEnabled()) {
                                    logger.debug("doSearch() search without date range");
                                }

                                hits = searcher.search(query);
                            }

                            // check for search with filesize
                            int numHits;
                            if (useSize.isSelected()) {
                                int minFilesize = 1;
                                int maxFilesize = 2;
                                try {
                                    minFilesize = Integer.parseInt(sizeFromField.getText()) * 1024;
                                    maxFilesize = Integer.parseInt(sizeToField.getText()) * 1024;
                                }
                                catch (Exception e) {
                                    setStatus(dsErrParseNums + " " + e.toString());
                                }
                                sizeList = getHitsForFilesizeRange(hits, minFilesize, maxFilesize);
                                numHits = sizeList[0].size();
                            }
                            else {
                                numHits = hits.length(); // NOT A SIZE QUERY
                            }

                            searchedIndexes.append("<li> <font color=\"blue\">");
                            searchedIndexes.append(currentIndex.getDescription());
                            searchedIndexes.append("</font> (<b>");
                            searchedIndexes.append(numHits);
                            searchedIndexes.append("</b>  &nbsp; ");
                            searchedIndexes.append(I18n.getString("documents"));
                            searchedIndexes.append(")</li>");
                            if (env.isGUIMode()) {
                                if (logger.isDebugEnabled()) {
                                    logger.debug("doSearch() " + I18n.getString("index") + ": " + currentIndex.getDescription());
                                }
                            }
                            else {
                                System.out.println(I18n.getString("index") + ": " + currentIndex.getDescription());
                            }
                            grandTotalHits += numHits;
                            tempBuf.append("<p align=\"center\"><b>");
                            tempBuf.append(numHits);
                            tempBuf.append("</b> &nbsp; ");
                            tempBuf.append(dsDocsFndInIndx);
                            tempBuf.append("<b>  &nbsp; ");
                            tempBuf.append(currentIndex.getDescription());
                            tempBuf.append("</b></p>");

                            curSrchPos++;
                            if (curSrchPos > 0) {
                                pPanel.setCurPos(curSrchPos);
                            }
                            for (int i = 0; i < numHits; i++) {
                                if (i > maxNumHitsShown) {
                                    setStatus(dsMxNumHits + " (" + maxNumHitsShown + ") " + I18n.getString("exceeded") + " (" + numHits + ").");
                                    break;
                                }

                                // get document and score from result or special result
                                Document currentDocument;
                                float currentScore;

                                // filesize result?
                                if (useSize.isSelected()) {
                                    currentDocument = (Document) sizeList[0].get(i);
                                    currentScore = ((Float) sizeList[1].get(i)).floatValue();
                                }
                                else {
                                    currentDocument = hits.doc(i);
                                    currentScore = hits.score(i);
                                }

                                // title
                                String currentTitle = Utils.convertTextToHTML(currentDocument.get(Index.FIELD_TITLE));

                                // filesize
                                String currentFilesize = currentDocument.get(Index.FIELD_SIZE);

                                // path or url
                                String currentFile;
                                if (! currentIndex.getIsWeb()) {
                                    if (! isCdRomIdx) {
                                        currentFile = currentDocument.get(Index.FIELD_PATH);
                                    }
                                    else {
                                        currentFile = getCDROMPath(currentDocument.get(Index.FIELD_URL));
                                    }
                                }
                                else {
                                    currentFile = currentDocument.get(Index.FIELD_URL);
                                }

                                // type
                                String currentTypeStr = currentDocument.get(Index.FIELD_TYPE);
                                FileType currentType = FileType.fromValue(currentTypeStr);

                                // author
                                String currentAuthor = currentDocument.get(Index.FIELD_AUTHOR);
                                if ("".equals(currentAuthor)) {
                                    currentAuthor = I18n.getString("unknown");
                                }

                                // date
                                String currentDate = currentDocument.get(Index.FIELD_MODDATE);
                                if ("".equals(currentDate)) {
                                    currentDate = I18n.getString("unknown");
                                }
                                else {
                                    currentDate = DateTimeUtils.getDateParsedFromIndex(currentDate);
                                }

                                String currentSummary = Utils.convertTextToHTML(currentDocument.get(Index.FIELD_SUMMARY));

                                // add it to our page - doc size title score
                                tempBuf.append("<p align=\"left\">");
                                if (! currentIndex.getIsWeb()) {
                                    tempBuf.append("<a href=\"");
                                    tempBuf.append(fileString);
                                    tempBuf.append(currentFile);
                                    tempBuf.append("\">");
                                }
                                else {
                                    tempBuf.append("<a href=\"");
                                    tempBuf.append(currentFile);
                                    tempBuf.append("\">");
                                }
                                if (hasIcons) {
                                    switch (currentType) {
                                        case HTML: // html
                                            tempBuf.append(htmlTag);
                                            break;
                                        case MS_WORD: // ms word
                                            tempBuf.append(wordTag);
                                            break;
                                        case MS_EXCEL: // ms excel
                                            tempBuf.append(excelTag);
                                            break;
                                        case PDF: // pdf
                                            tempBuf.append(pdfTag);
                                            break;
                                        case RTF: // rtf
                                            tempBuf.append(rtfTag);
                                            break;
                                        case OO_WRITER: // openoffice writer
                                            tempBuf.append(ooWriterTag);
                                            break;
                                        case OO_IMPRESS: // openoffice impress
                                            tempBuf.append(ooImpressTag);
                                            break;
                                        case OO_CALC: // openoffice calc
                                            tempBuf.append(ooCalcTag);
                                            break;
                                        case OO_DRAW: // openoffice draw
                                            tempBuf.append(ooDrawTag);
                                            break;
                                        case OPENDOCUMENT_TEXT: // opendocument text
                                            tempBuf.append(openDocumentTextTag);
                                            break;
                                        case TEXT:
                                            tempBuf.append(textTag);
                                            break;
                                        default:
                                          logger.error("doSearch() FileType." + currentType + " is not ok here!");
                                    }
                                }
                                else {
                                    tempBuf.append(currentTypeStr);
                                }
                                tempBuf.append(" ");
                                tempBuf.append(currentTitle);
                                tempBuf.append("</a><br>");
                                tempBuf.append(currentSummary);
                                tempBuf.append("<font color=\"green\"><br><em>");
                                tempBuf.append(currentDate);
                                tempBuf.append(", ");
                                tempBuf.append(Utils.getKStyle(currentFilesize));
                                tempBuf.append("bytes, ");
                                tempBuf.append(currentAuthor);
                                tempBuf.append(", <b>");
                                tempBuf.append(Utils.getPercentStringFromScore(currentScore));
                                tempBuf.append("</b></em></font><br><font color=\"gray\">");
                                tempBuf.append(currentFile);
                                tempBuf.append("</font>");
                                tempBuf.append("</p>");
                                if (env.isGUIMode()) {
                                    if (logger.isDebugEnabled()) {
                                        logger.debug("doSearch() \n\n* " + currentTitle + "\n" + currentSummary + "\n" + currentDate + ", " +
                                                Utils.getKStyle(currentFilesize) + "bytes, " + currentAuthor + ", " +
                                                Utils.getPercentStringFromScore(currentScore) + "\n" + currentFile);
                                    }
                                }
                                else {
                                    System.out.println("\n\n* " + currentTitle + "\n" + currentSummary + "\n" + currentDate + ", " +
                                            Utils.getKStyle(currentFilesize) + "bytes, " + currentAuthor + ", " +
                                            Utils.getPercentStringFromScore(currentScore) + "\n" + currentFile);
                                }
                            } // end for hits
                            // now add our results
                            curSrchPos++;
                            if (curSrchPos > 0) {
                                pPanel.setCurPos(curSrchPos);
                            }
                            // add the footer
                            bodyBuf.append(tempBuf);

                            // close index
                            searcher.close();
                        } // end if shouldbesearched
                        else {
                            tempBuf.append("<p align=\"left\">");
                            tempBuf.append(I18n.getString("index"));
                            tempBuf.append("  &nbsp; <b>");
View Full Code Here

                Document doc = hits.doc(i + offset);
                float score = hits.score(i + offset);
            ## LUCENE2 end ##*/
            //## LUCENE3 begin ##
            // take a reference as the searcher may change
            Searcher searcher = access.searcher;
            // 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;
            TopDocs docs = searcher.search(query, maxResults);
            if (limit == 0) {
                limit = docs.totalHits;
            }
            for (int i = 0, len = docs.scoreDocs.length;
                    i < limit && i + offset < docs.totalHits
                    && i + offset < len; i++) {
                ScoreDoc sd = docs.scoreDocs[i + offset];
                Document doc = searcher.doc(sd.doc);
                float score = sd.score;
                //## LUCENE3 end ##
                String q = doc.get(LUCENE_FIELD_QUERY);
                if (data) {
                    int idx = q.indexOf(" WHERE ");
View Full Code Here

        //Whether to optimize automatically after an add/remove/update.
        doOptimize = serviceConf.getBoolean(CONFIG_AUTO_OPTIMIZE, DEFAULT_AUTO_OPTIMIZE);

        try
        {
            Searcher searcher = null;
            searcher = new IndexSearcher(rootDir.getPath());
            searcher.close();
        }
        catch (Exception e)
        {
            try
            {
View Full Code Here

TOP

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

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.