Examples of IndexReader


Examples of org.apache.lucene.index.IndexReader

  public String[] suggest(String queryString, IndexReader idxReader, String field){
    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){
          try {
            indexReader.close();
          } catch (IOException e) {
            logger.error(e);
          }
        }
      }   
View Full Code Here

Examples of org.apache.lucene.index.IndexReader

   *            a URL MD5 Hash.
   *
   * @return a Lucene document of the representative bookmark
   */
  public Document findLeadDocument(String urlHash) {
    IndexReader reader = null;
    TermDocs termDocs = null;
    Document leadDoc = null;
    try {
      boolean exists = IndexReader.indexExists(indexDirectory);
      if (exists == true) {
        reader = IndexReader.open(indexDirectory);
        Term key = new Term(DocumentCreator.FIELD_URL_MD5, urlHash);
        termDocs = reader.termDocs(key);
        boolean found = false;
        while (termDocs.next() && found == false) {
          int pos = termDocs.doc();
          // use FieldSelector for more efficient loading of Fields.
          // load only what's needed to determine a leading document
          Document d = reader.document(pos, new FieldSelector() {
            private static final long serialVersionUID = 1426724242925499003L;

            public FieldSelectorResult accept(String field) {
              if (field.equals(DocumentCreator.FIELD_INDEX_TYPE)) {
                return FieldSelectorResult.LOAD_AND_BREAK;
              } else {
                return FieldSelectorResult.NO_LOAD;
              }
            }
          });
          String[] values = d
              .getValues(DocumentCreator.FIELD_INDEX_TYPE);
          if (values != null) {
            List<String> vList = Arrays.asList(values);
            if (vList.contains(DocumentCreator.INDEX_TYPE_LEAD) == true) {
              leadDoc = reader.document(pos);
              found = true;
            }
          }
        }
      }
    } catch (Exception e) {
      logger.error("FindLeadDocument failed to find doc: " + urlHash
          + ", exception=" + e);
    } finally {
      try {
        if (termDocs != null) {
          termDocs.close();
        }
        if (reader != null) {
          reader.close();
        }
      } catch (Exception e) {
        logger
            .error("FindLeadDocument can't close reader or termDocs: "
                + e);
View Full Code Here

Examples of org.apache.lucene.index.IndexReader

   *            a URL MD5 Hash.
   *
   * @return a Lucene document of a non-representative bookmark
   */
  public Document findNonLeadDocument(String urlHash) {
    IndexReader reader = null;
    TermDocs termDocs = null;
    Document leadDoc = null;
    try {
      boolean exists = IndexReader.indexExists(indexDirectory);
      if (exists == true) {
        reader = IndexReader.open(indexDirectory);
        Term key = new Term(DocumentCreator.FIELD_URL_MD5, urlHash);
        termDocs = reader.termDocs(key);
        boolean found = false;
        while (termDocs.next() && found == false) {
          int pos = termDocs.doc();
          // use FieldSelector for more efficient loading of Fields.
          // load only what's needed to determine a leading document
          Document d = reader.document(pos, new FieldSelector() {
            private static final long serialVersionUID = 1426724242925499003L;

            public FieldSelectorResult accept(String field) {
              if (field.equals(DocumentCreator.FIELD_INDEX_TYPE)) {
                return FieldSelectorResult.LOAD_AND_BREAK;
              } else {
                return FieldSelectorResult.NO_LOAD;
              }
            }

          });
          String[] values = d
              .getValues(DocumentCreator.FIELD_INDEX_TYPE);
          if (values != null) {
            List<String> vList = Arrays.asList(values);
            if (vList.contains(DocumentCreator.INDEX_TYPE_LEAD) == false) {
              leadDoc = reader.document(pos);
              found = true;
            }
          } else {
            leadDoc = reader.document(pos);
            found = true;
          }
        }
      }
    } catch (Exception e) {
      logger.error("FindLeadDocument failed to find doc hash: " + urlHash
          + ", exception=" + e);
    } finally {
      try {
        if (termDocs != null) {
          termDocs.close();
        }
        if (reader != null) {
          reader.close();
        }
      } catch (Exception e) {
        logger
            .error("FindLeadDocument can't close reader or termDocs: "
                + e);
View Full Code Here

Examples of org.fastlsh.index.IndexReader

     * @throws ClassNotFoundException
     * @throws InvalidIndexException
     */
    public NearestNeighborSearcher(String indexDir) throws FileNotFoundException, IOException, ClassNotFoundException, InvalidIndexException
    {
        reader = new IndexReader(indexDir);
        reader.initializeOptions();
        reader.initializePermutationIndex();
        reader.initializePermutationLists();
        reader.initializeRawVecs();
        rawVectorMap = reader.rawVectorMap;
View Full Code Here

Examples of org.jboss.jandex.IndexReader

            final Set<Index> indexes = new HashSet<Index>();
            while (resources.hasMoreElements()) {
                final URL url = resources.nextElement();
                InputStream stream = url.openStream();
                try {
                    IndexReader reader = new IndexReader(stream);
                    indexes.add(reader.read());
                } finally {
                    stream.close();
                }
            }
            return new CompositeIndex(indexes);
View Full Code Here

Examples of org.solbase.lucenehbase.IndexReader

      if (indexName == null)
        throw new IOException("Missing core name");

      logger.debug(indexName);
      IndexReader reader = (IndexReader) ((SolrIndexReader) rb.req.getSearcher().getIndexReader()).getWrappedReader();
     
      reader.setIndexName(indexName);

      return;
    }

    String indexName = rb.req.getCore().getName();

    if (indexName.equals("")) {
      return; //
    } else {
      logger.debug("core: " + indexName);
    }

    if (rb.shards == null) {
          // find number of shards
      // this is current max doc id
            // for real time, we'd have to fetch max doc id from table. maybe put some caching around this number
      //int docId = SolbaseUtil.getSequenceId();

            int numShards = SolbaseShardUtil.getNumShard();

            //run local
            if(numShards == 0) {
                IndexReader reader = (IndexReader) ((SolrIndexReader) rb.req.getSearcher().getIndexReader())
                .getWrappedReader();

                String subIndex = indexName;
                reader.setIndexName(subIndex);
                                                                                                                                                            
                return;
            }  
                
           
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.