Package org.apache.lucene.search

Examples of org.apache.lucene.search.IndexSearcher


    } catch (Exception e) {
      if(DebugFile.trace)
        DebugFile.writeln(e.getMessage());
    }
  }
    IndexSearcher oSearch = new IndexSearcher(sSegments);
   
    Document oDoc;

    ContactRecord aRetArr[] = null;
    //Recorremos los resultados y los vamos añadiendo al map
   
      TopDocs oTopSet = oSearch.search(oQry, null, 20);
      if (oTopSet.scoreDocs!=null) {
        ScoreDoc[] oTopDoc = oTopSet.scoreDocs;
        int iDocCount = oTopDoc.length;
        aRetArr = new ContactRecord[iDocCount];
        for (int d=0; d<iDocCount; d++) {
          oDoc = oSearch.doc(oTopDoc[d].doc);
         // String[] aAbstract = Gadgets.split(oSearch.doc(oTopDoc[d].doc).get("abstract"), '¨');
          aRetArr[d] = new ContactRecord(oTopDoc[d].score,oDoc.get("author"),
                oDoc.get("workarea"),oDoc.get("guid"),oDoc.get("value"));
        } // next
      } else {
        aRetArr = null;
      }
  
    oSearch.close();

    if (DebugFile.trace) {
      DebugFile.decIdent();
      if (null==aRetArr)
        DebugFile.writeln("End ContactSearcher.search() : no records found");
View Full Code Here


  oQrx.add(oQry, BooleanClause.Occur.MUST);
 
  String sSegments = Gadgets.chomp(sLuceneIndexPath,File.separator)+"k_newsmsgs"+File.separator+sWorkArea; 
    if (DebugFile.trace) DebugFile.writeln("new IndexSearcher("+sSegments+")");
    IndexSearcher oSearch = new IndexSearcher(sSegments);

    Document oDoc;

    if (iLimit>0) {
      System.out.println("IndexSearcher.search("+oQrx.toString()+")");
      if (DebugFile.trace) DebugFile.writeln("IndexSearcher.search("+oQrx.toString()+")");
      TopDocs oTopSet = oSearch.search(oQrx, null, iLimit);
      if (oTopSet.scoreDocs!=null) {
        ScoreDoc[] oTopDoc = oTopSet.scoreDocs;
        int iDocCount = oTopDoc.length;
        aRetArr = new NewsMessageRecord[iDocCount];
        for (int d=0; d<iDocCount; d++) {
          oDoc = oSearch.doc(oTopDoc[d].doc);
          String[] aAbstract = Gadgets.split(oSearch.doc(oTopDoc[d].doc).get("abstract"), '¨');
          try {
            aRetArr[d] = new NewsMessageRecord(oTopDoc[d].score, oDoc.get("workarea"),
                         oDoc.get("guid"), oDoc.get("container"), oDoc.get("title"),                      
                         oDoc.get("author"), DateTools.stringToDate(oDoc.get("created")), oDoc.get("abstract"));
          } catch (java.text.ParseException neverthrown) {
            throw new ParseException("NewsMessageSearcher.search() Error parsing date "+oDoc.get("created")+" of document "+oDoc.get("guid"));
          }
        } // next
      } else {
        aRetArr = null;
      }
    } else {
      Hits oHitSet = oSearch.search(oQrx);
      int iHitCount = oHitSet.length();
      if (iHitCount>0) {
        aRetArr = new NewsMessageRecord[iHitCount];
        for (int h=0; h<iHitCount; h++) {
          oDoc = oHitSet.doc(h);
View Full Code Here

    addDoc("3", new String[]{ "aa","bb"}, new String[]{"bbb","aaa"}, new int[]{300,300});
    addDoc("3", new String[]{ "bb","aa"}, new String[]{"bbb","bbb"}, new int[]{300,400});
    addDoc("3", new String[]{ "bb","aa"}, new String[]{"aaa","ccc"}, new int[]{300,500});
    writer.commit();
    IndexReader reader = IndexReader.open(directory, true);
    searcher = new IndexSearcher(reader);
    IndexReader readerWithCache = new IndexReaderWithMetaDataCache(reader);
    searcherWithCache = new IndexSearcher(readerWithCache);
  }
View Full Code Here

    // Open the mIndexSearcher in SEARCHING_MODE
    if ((mode == SEARCHING_MODE) && (mIndexSearcher == null)) {
      mLog.info("Switching to index mode: searching mode");
      try {
        mIndexSearcher = new IndexSearcher(mLuceneTempIndexDir, false);
      } catch (IOException exc) {
        throw new RegainException("Creating IndexSearcher failed", exc);
      }
    }
View Full Code Here

      if (! mWorkingIndexDir.exists()) {
        checkForIndexUpdate();
      }

      try {
        mIndexSearcher = new IndexSearcher(FSDirectory.open(mWorkingIndexDir),true);
      }
      catch (IOException exc) {
        throw new RegainException("Creating index searcher failed", exc);
      }
    }
View Full Code Here

      if (! mWorkingIndexDir.exists()) {
        checkForIndexUpdate();
      }

      try {
        mIndexSearcher = new IndexSearcher(FSDirectory.open(mWorkingIndexDir),true);
      }
      catch (IOException exc) {
        throw new RegainException("Creating index searcher failed", exc);
      }
    }
View Full Code Here

   * @throws ParseException
   */
  public DaoResult<BookmarkDoc> searchAll(String query, int offset, int count)
      throws IOException, ParseException {
    DaoResult<BookmarkDoc> result = null;
    IndexSearcher searcher = null;
    try {
      File directory = searchIndexManager.getIndexDirectory();
      searcher = new IndexSearcher(IndexReader.open(directory));
      Analyzer analyzer = DocumentCreator.createDocumentAnalyzer();
      QueryParser parser = new QueryParser(DocumentCreator.FIELD_TEXT,analyzer);
      Hits hits = searcher.search(parser.parse(query));
      List<BookmarkDoc> bmDocs = new ArrayList<BookmarkDoc>();
      if (offset >= 0 && offset < hits.length()) {
        if (count > 0) {         
          for (int i = offset; i < hits.length() && bmDocs.size() < count; i++) {
            BookmarkDoc doc = createBookmarkDoc(hits.doc(i));
            if (doc != null) {
              bmDocs.add(doc);
            }
          }
        }
      }
      result = new DaoResult<BookmarkDoc>(bmDocs,hits.length());
    } finally {
      if (searcher != null) {
        searcher.close();
      }
    }
    return result;
  }
View Full Code Here

   * @throws ParseException
   */
  public DaoResult<BookmarkDoc> searchUser(String query, String username, int offset, int count)
    throws IOException, ParseException{
    DaoResult<BookmarkDoc> result = null;
    IndexSearcher searcher = null;
    try {
      File directory = searchIndexManager.getIndexDirectory();
      searcher = new IndexSearcher(IndexReader.open(directory));
      Analyzer analyzer = DocumentCreator.createDocumentAnalyzer();
      QueryParser parser = new QueryParser(DocumentCreator.FIELD_TEXT,analyzer);
     
      TermQuery matchUserQuery = new TermQuery(new Term(DocumentCreator.FIELD_USER,username));
      Query inputQuery = parser.parse(query);
      BooleanQuery boolQuery = new BooleanQuery();
      boolQuery.add(matchUserQuery, BooleanClause.Occur.MUST);
      boolQuery.add(inputQuery,BooleanClause.Occur.MUST);
     
      Hits hits = searcher.search(boolQuery);
      List<BookmarkDoc> bmDocs = new ArrayList<BookmarkDoc>();
      if (offset >= 0 && offset < hits.length()) {
        if (count > 0) {         
          for (int i = offset; i < hits.length() && bmDocs.size() < count; i++) {
            BookmarkDoc doc = createBookmarkDoc(hits.doc(i));
            if (doc != null) {
              bmDocs.add(doc);
            }
          }
        }
      }
      result = new DaoResult<BookmarkDoc>(bmDocs,hits.length());
    } finally {
      if (searcher != null) {
        searcher.close();
      }
    }
    return result;
  }
View Full Code Here

    List<String> results = new ArrayList<String>(maxSuggestionSize);
    if(queryString != null && queryString.length() >= minQueryStringLength){
      Term term = new Term("t", queryString);
      PrefixQuery prefixQuery = new PrefixQuery(term);
      IndexReader indexReader = null;
      IndexSearcher indexSearch = null;
      try{
        indexReader = searchSuggestIndexer.openSuggestIndexReader();
        indexSearch = new IndexSearcher(indexReader);
        Hits hits = indexSearch.search(prefixQuery);
        int maxNumCandidate = maxSuggestionSize;
        if(idxReader != null && field != null){
          maxNumCandidate = maxSuggestionSize * 10;
        }
        PriorityQueue<SuggestWord> suggestQueue = new PriorityQueue<SuggestWord>(maxNumCandidate);
        for(int i = 0; i < hits.length() && i < maxNumCandidate; i++){
          String sugWord = hits.doc(i).get("t");
          // check if the 'sugWord' matches at least one doc in the
          // source index database (idxReader)
          if(idxReader != null && field != null){
            int freq = idxReader.docFreq(new Term(field,sugWord));
            if(freq > 0){
              suggestQueue.add(new SuggestWord(sugWord,freq));
            }
          }else{
            suggestQueue.add(new SuggestWord(sugWord,0));
          }         
        }
        int qSize = suggestQueue.size();
        for(int i = 0; i < maxSuggestionSize && i < qSize; i++){
          SuggestWord word = suggestQueue.poll();
          results.add(word.getWord());
        }
      }catch(Exception e){
        logger.error(e);
      }finally{
        try {
          if(indexSearch != null){
            indexSearch.close();
          }
        } catch (IOException e) {
          logger.error(e);
        }
        if(indexReader != null){
View Full Code Here

          document.getDocument().getField(SearchDocument.ENTITY_ID_TEXT).setValue(String.valueOf(i));
          indexWriter.addDocument(document.getDocument());
        }
        indexWriter.close();

        searcher[0] = new IndexSearcher(directory);
      } catch (Exception e) {
        directory.close();
        throw e;
      }
    }
View Full Code Here

TOP

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

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.