⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 indexmodifier.java

📁 Lucene a java open-source SearchEngine Framework
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   * @throws StaleReaderException if the index has changed   *  since this reader was opened   * @throws CorruptIndexException if the index is corrupt   * @throws LockObtainFailedException if another writer   *  has this index open (<code>write.lock</code> could not   *  be obtained)   * @throws IOException if there is a low-level IO error   */  public int deleteDocuments(Term term) throws StaleReaderException, CorruptIndexException, LockObtainFailedException, IOException {    synchronized(directory) {      assureOpen();      createIndexReader();      return indexReader.deleteDocuments(term);    }  }  /**   * Deletes the document numbered <code>docNum</code>.   * @see IndexReader#deleteDocument(int)   * @throws StaleReaderException if the index has changed   *  since this reader was opened   * @throws CorruptIndexException if the index is corrupt   * @throws LockObtainFailedException if another writer   *  has this index open (<code>write.lock</code> could not   *  be obtained)   * @throws IllegalStateException if the index is closed   */  public void deleteDocument(int docNum) throws StaleReaderException, CorruptIndexException, LockObtainFailedException, IOException {    synchronized(directory) {      assureOpen();      createIndexReader();      indexReader.deleteDocument(docNum);    }  }  /**   * Returns the number of documents currently in this   * index.  If the writer is currently open, this returns   * {@link IndexWriter#docCount()}, else {@link   * IndexReader#numDocs()}.  But, note that {@link   * IndexWriter#docCount()} does not take deletions into   * account, unlike {@link IndexReader#numDocs}.   * @throws IllegalStateException if the index is closed   */  public int docCount() {    synchronized(directory) {      assureOpen();      if (indexWriter != null) {        return indexWriter.docCount();      } else {        return indexReader.numDocs();      }    }  }  /**   * Merges all segments together into a single segment, optimizing an index   * for search.   * @see IndexWriter#optimize()   * @throws IllegalStateException if the index is closed   * @throws CorruptIndexException if the index is corrupt   * @throws LockObtainFailedException if another writer   *  has this index open (<code>write.lock</code> could not   *  be obtained)   * @throws IOException if there is a low-level IO error   */  public void optimize() throws CorruptIndexException, LockObtainFailedException, IOException {    synchronized(directory) {      assureOpen();      createIndexWriter();      indexWriter.optimize();    }  }  /**   * If non-null, information about merges and a message when   * {@link #getMaxFieldLength()} is reached will be printed to this.   * <p>Example: <tt>index.setInfoStream(System.err);</tt>   * @see IndexWriter#setInfoStream(PrintStream)   * @throws IllegalStateException if the index is closed   */  public void setInfoStream(PrintStream infoStream) {    synchronized(directory) {      assureOpen();      if (indexWriter != null) {        indexWriter.setInfoStream(infoStream);      }      this.infoStream = infoStream;    }  }  /**   * @see IndexModifier#setInfoStream(PrintStream)   * @throws CorruptIndexException if the index is corrupt   * @throws LockObtainFailedException if another writer   *  has this index open (<code>write.lock</code> could not   *  be obtained)   * @throws IOException if there is a low-level IO error   */  public PrintStream getInfoStream() throws CorruptIndexException, LockObtainFailedException, IOException {    synchronized(directory) {      assureOpen();      createIndexWriter();      return indexWriter.getInfoStream();    }  }  /**   * Setting to turn on usage of a compound file. When on, multiple files   * for each segment are merged into a single file once the segment creation   * is finished. This is done regardless of what directory is in use.   * @see IndexWriter#setUseCompoundFile(boolean)   * @throws IllegalStateException if the index is closed   */  public void setUseCompoundFile(boolean useCompoundFile) {    synchronized(directory) {      assureOpen();      if (indexWriter != null) {        indexWriter.setUseCompoundFile(useCompoundFile);      }      this.useCompoundFile = useCompoundFile;    }  }  /**   * @see IndexModifier#setUseCompoundFile(boolean)   * @throws CorruptIndexException if the index is corrupt   * @throws LockObtainFailedException if another writer   *  has this index open (<code>write.lock</code> could not   *  be obtained)   * @throws IOException if there is a low-level IO error   */  public boolean getUseCompoundFile() throws CorruptIndexException, LockObtainFailedException, IOException {    synchronized(directory) {      assureOpen();      createIndexWriter();      return indexWriter.getUseCompoundFile();    }  }  /**   * The maximum number of terms that will be indexed for a single field in a   * document.  This limits the amount of memory required for indexing, so that   * collections with very large files will not crash the indexing process by   * running out of memory.<p/>   * Note that this effectively truncates large documents, excluding from the   * index terms that occur further in the document.  If you know your source   * documents are large, be sure to set this value high enough to accomodate   * the expected size.  If you set it to Integer.MAX_VALUE, then the only limit   * is your memory, but you should anticipate an OutOfMemoryError.<p/>   * By default, no more than 10,000 terms will be indexed for a field.   * @see IndexWriter#setMaxFieldLength(int)   * @throws IllegalStateException if the index is closed   */  public void setMaxFieldLength(int maxFieldLength) {    synchronized(directory) {      assureOpen();      if (indexWriter != null) {        indexWriter.setMaxFieldLength(maxFieldLength);      }      this.maxFieldLength = maxFieldLength;    }  }  /**   * @see IndexModifier#setMaxFieldLength(int)   * @throws CorruptIndexException if the index is corrupt   * @throws LockObtainFailedException if another writer   *  has this index open (<code>write.lock</code> could not   *  be obtained)   * @throws IOException if there is a low-level IO error   */  public int getMaxFieldLength() throws CorruptIndexException, LockObtainFailedException, IOException {    synchronized(directory) {      assureOpen();      createIndexWriter();      return indexWriter.getMaxFieldLength();    }  }  /**   * Determines the minimal number of documents required before the buffered   * in-memory documents are merging and a new Segment is created.   * Since Documents are merged in a {@link org.apache.lucene.store.RAMDirectory},   * large value gives faster indexing.  At the same time, mergeFactor limits   * the number of files open in a FSDirectory.   *   * <p>The default value is 10.   *   * @see IndexWriter#setMaxBufferedDocs(int)   * @throws IllegalStateException if the index is closed   * @throws IllegalArgumentException if maxBufferedDocs is smaller than 2   */  public void setMaxBufferedDocs(int maxBufferedDocs) {    synchronized(directory) {      assureOpen();      if (indexWriter != null) {        indexWriter.setMaxBufferedDocs(maxBufferedDocs);      }      this.maxBufferedDocs = maxBufferedDocs;    }  }  /**   * @see IndexModifier#setMaxBufferedDocs(int)   * @throws CorruptIndexException if the index is corrupt   * @throws LockObtainFailedException if another writer   *  has this index open (<code>write.lock</code> could not   *  be obtained)   * @throws IOException if there is a low-level IO error   */  public int getMaxBufferedDocs() throws CorruptIndexException, LockObtainFailedException, IOException {    synchronized(directory) {      assureOpen();      createIndexWriter();      return indexWriter.getMaxBufferedDocs();    }  }  /**   * Determines how often segment indices are merged by addDocument().  With   * smaller values, less RAM is used while indexing, and searches on   * unoptimized indices are faster, but indexing speed is slower.  With larger   * values, more RAM is used during indexing, and while searches on unoptimized   * indices are slower, indexing is faster.  Thus larger values (&gt; 10) are best   * for batch index creation, and smaller values (&lt; 10) for indices that are   * interactively maintained.   * <p>This must never be less than 2.  The default value is 10.   *   * @see IndexWriter#setMergeFactor(int)   * @throws IllegalStateException if the index is closed   */  public void setMergeFactor(int mergeFactor) {    synchronized(directory) {      assureOpen();      if (indexWriter != null) {        indexWriter.setMergeFactor(mergeFactor);      }      this.mergeFactor = mergeFactor;    }  }  /**   * @see IndexModifier#setMergeFactor(int)   * @throws CorruptIndexException if the index is corrupt   * @throws LockObtainFailedException if another writer   *  has this index open (<code>write.lock</code> could not   *  be obtained)   * @throws IOException if there is a low-level IO error   */  public int getMergeFactor() throws CorruptIndexException, LockObtainFailedException, IOException {    synchronized(directory) {      assureOpen();      createIndexWriter();      return indexWriter.getMergeFactor();    }  }  /**   * Close this index, writing all pending changes to disk.   *   * @throws IllegalStateException if the index has been closed before already   * @throws CorruptIndexException if the index is corrupt   * @throws IOException if there is a low-level IO error   */  public void close() throws CorruptIndexException, IOException {    synchronized(directory) {      if (!open)        throw new IllegalStateException("Index is closed already");      if (indexWriter != null) {        indexWriter.close();        indexWriter = null;      } else if (indexReader != null) {        indexReader.close();        indexReader = null;      }      open = false;    }  }  public String toString() {    return "Index@" + directory;  }  /*  // used as an example in the javadoc:  public static void main(String[] args) throws IOException {    Analyzer analyzer = new StandardAnalyzer();    // create an index in /tmp/index, overwriting an existing one:    IndexModifier indexModifier = new IndexModifier("/tmp/index", analyzer, true);    Document doc = new Document();    doc.add(new Fieldable("id", "1", Fieldable.Store.YES, Fieldable.Index.UN_TOKENIZED));    doc.add(new Fieldable("body", "a simple test", Fieldable.Store.YES, Fieldable.Index.TOKENIZED));    indexModifier.addDocument(doc);    int deleted = indexModifier.delete(new Term("id", "1"));    System.out.println("Deleted " + deleted + " document");    indexModifier.flush();    System.out.println(indexModifier.docCount() + " docs in index");    indexModifier.close();  }*/  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -