Package org.apache.lucene.index

Examples of org.apache.lucene.index.IndexReader$FieldOption


   * @param args
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    addIndex();
    IndexReader reader = IndexReader.open(lucenePath);
    System.out.println("�ĵ���:"+reader.numDocs());
    TermEnum tes = reader.terms();
    while(tes.next()){
      Term t = tes.term();
      System.out.println(t.toString());
    }
    //IndexSearcher searcher = new IndexSearcher(lucenePath);
View Full Code Here


   */
  public static synchronized int remove(SearchEnabled doc){
    if(doc == null)
      return -1;
   
    IndexReader reader = null;
    try{
      reader = getReader(doc.name())
      String pvalue = getField(doc, doc.getKeywordField());
      Term keyTerm = new Term(doc.getKeywordField(), pvalue);
      return reader.deleteDocuments(keyTerm);
    }catch(Exception e){
      log.error("Error where delete index of "+ doc, e);
    }finally{
      if(reader!=null)
      try{
        reader.close();
      }catch(Exception e){
        log.error("Error occur when closing IndexReader", e);
      }finally{
        reader = null;
      }
View Full Code Here

    IndexReader[] readers = new IndexReader[length];
    if ( trace ) log.trace( "Opening IndexReader for directoryProviders: " + length );

    for (int index = 0; index < length; index++) {
      DirectoryProvider directoryProvider = directoryProviders[index];
      IndexReader reader;
      Lock directoryProviderLock = perDirectoryProviderManipulationLocks.get( directoryProvider );
      if ( trace ) log.trace( "Opening IndexReader from " + directoryProvider.getDirectory().toString() );
      directoryProviderLock.lock(); //needed for same problem as the double-checked locking
      try {
        reader = activeSearchIndexReaders.get( directoryProvider );
      }
      finally {
        directoryProviderLock.unlock();
      }
      if ( reader == null ) {
        if ( trace )
          log.trace( "No shared IndexReader, opening a new one: " + directoryProvider.getDirectory().toString() );
        reader = replaceActiveReader( null, directoryProviderLock, directoryProvider, readers );
      }
      else {
        boolean isCurrent;
        try {
          isCurrent = reader.isCurrent();
        }
        catch (IOException e) {
          throw new SearchException( "Unable to read current status of Lucene IndexReader", e );
        }
        if ( !isCurrent ) {
          if ( trace )
            log.trace( "Out of date shared IndexReader found, opening a new one: " + directoryProvider.getDirectory().toString() );
          IndexReader outOfDateReader = reader;
          reader = replaceActiveReader( outOfDateReader, directoryProviderLock, directoryProvider, readers );
        }
        else {
          if ( trace )
            log.trace( "Valid shared IndexReader: " + directoryProvider.getDirectory().toString() );
View Full Code Here

    return buildMultiReader( length, readers );
  }

  private IndexReader replaceActiveReader(IndexReader outOfDateReader, Lock directoryProviderLock, DirectoryProvider directoryProvider, IndexReader[] readers) {
    boolean trace = log.isTraceEnabled();
    IndexReader oldReader;
    boolean closeOldReader = false;
    boolean closeOutOfDateReader = false;
    IndexReader reader;
    /**
     * Since out of lock protection, can have multiple readers created in //
     * not worse than NotShared and limit the locking time, hence scalability
     */
    try {
View Full Code Here

                    boolean recreate = !IndexReader.indexExists(indexDir);
                    Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);
                    IndexWriter writer = new IndexWriter(indexDir, analyzer,
                            recreate, IndexWriter.MaxFieldLength.UNLIMITED);
                    //see http://wiki.apache.org/lucene-java/NearRealtimeSearch
                    IndexReader reader = writer.getReader();
                    access = new IndexAccess();
                    access.writer = writer;
                    access.reader = reader;
                    access.searcher = new IndexSearcher(reader);
                    //## LUCENE3 end ##
View Full Code Here

                indexAccess.writer.addDocument(doc);
                indexAccess.writer.commit();
                // recreate Searcher with the IndexWriter's reader.
                indexAccess.searcher.close();
                indexAccess.reader.close();
                IndexReader reader = indexAccess.writer.getReader();
                indexAccess.reader = reader;
                indexAccess.searcher = new IndexSearcher(reader);
            } catch (IOException e) {
                throw convertException(e);
            }
View Full Code Here

          }
        }

        if (readerDir != null)
        {
          IndexReader     reader = IndexReader.open(readerDir);
          SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span class=\"highlighted\">", "</span>");

          mHighlighter = new Highlighter(formatter, new QueryScorer(query.rewrite(reader)));
        }
        else
View Full Code Here

              .append(channel.getName().substring(1));
           
            if (submission.getChannel() == null ||
              submission.getChannel().equals(""))
            {
              IndexReader   r = IndexReader.open(key.toString());
              IndexSearcher   s = new IndexSearcher(r);

              searchers.add(s);
              readers.add(r);
            }
            else
            {
              String submissionChannel = submission.getChannel().substring(submission.getChannel().indexOf("#"));
              if (channel.getName().equals(submissionChannel))
              {
                IndexReader   r = IndexReader.open(key.toString());
                IndexSearcher   s = new IndexSearcher(r);

                searchers.add(s);
                readers.add(r);
              }
View Full Code Here

  private BoboIndexReader newIndexReader() throws IOException{
    return newIndexReader(true);
  }
 
  private BoboIndexReader newIndexReader(boolean readonly) throws IOException{
    IndexReader srcReader=IndexReader.open(_indexDir,readonly);
      try{
        BoboIndexReader reader= BoboIndexReader.getInstance(srcReader,_fconf, null);
        return reader;
      }
      catch(IOException ioe){
        if (srcReader!=null){
          srcReader.close();
        }
        throw ioe;
      }
  }
View Full Code Here

      Document[] data=buildData();
     
      TestDataDigester testDigester=new TestDataDigester(_fconf,data);
      BoboIndexer indexer=new BoboIndexer(testDigester,idxDir);
      indexer.index();
      IndexReader r = IndexReader.open(idxDir,false);
      r.deleteDocument(r.maxDoc() - 1);
      //r.flush();
      r.close();
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.IndexReader$FieldOption

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.