Java Doc for IndexModifier.java in  » Net » lucene-connector » org » apache » lucene » index » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » lucene connector » org.apache.lucene.index 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.lucene.index.IndexModifier

IndexModifier
public class IndexModifier (Code)

[Note that as of 2.1, all but one of the methods in this class are available via IndexWriter . The one method that is not available is IndexModifier.deleteDocument(int) .]

A class to modify an index, i.e. to delete and add documents. This class hides IndexReader and IndexWriter so that you do not need to care about implementation details such as that adding documents is done via IndexWriter and deletion is done via IndexReader.

Note that you cannot create more than one IndexModifier object on the same directory at the same time.

Example usage:

    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 Field("id""1", Field.Store.YES, Field.Index.UN_TOKENIZED));
    doc.add(new Field("body""a simple test", Field.Store.YES, Field.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();

Not all methods of IndexReader and IndexWriter are offered by this class. If you need access to additional methods, either use those classes directly or implement your own class that extends IndexModifier.

Although an instance of this class can be used from more than one thread, you will not get the best performance. You might want to use IndexReader and IndexWriter directly for that (but you will need to care about synchronization yourself then).

While you can freely mix calls to add() and delete() using this class, you should batch you calls for best performance. For example, if you want to update 20 documents, you should first delete all those documents, then add all the new documents.
author:
   Daniel NaberIndexWriter



Field Summary
protected  Analyzeranalyzer
    
protected  Directorydirectory
    
protected  IndexReaderindexReader
    
protected  IndexWriterindexWriter
    
protected  PrintStreaminfoStream
    
protected  intmaxBufferedDocs
    
protected  intmaxFieldLength
    
protected  intmergeFactor
    
protected  booleanopen
    
protected  booleanuseCompoundFile
    

Constructor Summary
public  IndexModifier(Directory directory, Analyzer analyzer, boolean create)
     Open an index with write access.
public  IndexModifier(String dirName, Analyzer analyzer, boolean create)
     Open an index with write access.
public  IndexModifier(File file, Analyzer analyzer, boolean create)
     Open an index with write access.

Method Summary
public  voidaddDocument(Document doc, Analyzer docAnalyzer)
     Adds a document to this index, using the provided analyzer instead of the one specific in the constructor.
public  voidaddDocument(Document doc)
     Adds a document to this index.
protected  voidassureOpen()
     Throw an IllegalStateException if the index is closed.
public  voidclose()
     Close this index, writing all pending changes to disk.
protected  voidcreateIndexReader()
     Close the IndexWriter and open an IndexReader.
protected  voidcreateIndexWriter()
     Close the IndexReader and open an IndexWriter.
public  voiddeleteDocument(int docNum)
     Deletes the document numbered docNum.
public  intdeleteDocuments(Term term)
     Deletes all documents containing term. This is useful if one uses a document field to hold a unique ID string for the document.
public  intdocCount()
     Returns the number of documents currently in this index.
public  voidflush()
     Make sure all changes are written to disk.
public  PrintStreamgetInfoStream()
    
public  intgetMaxBufferedDocs()
    
public  intgetMaxFieldLength()
    
public  intgetMergeFactor()
    
public  booleangetUseCompoundFile()
    
protected  voidinit(Directory directory, Analyzer analyzer, boolean create)
     Initialize an IndexWriter.
public  voidoptimize()
     Merges all segments together into a single segment, optimizing an index for search.
public  voidsetInfoStream(PrintStream infoStream)
     If non-null, information about merges and a message when IndexModifier.getMaxFieldLength() is reached will be printed to this.
public  voidsetMaxBufferedDocs(int maxBufferedDocs)
     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 org.apache.lucene.store.RAMDirectory , large value gives faster indexing.
public  voidsetMaxFieldLength(int maxFieldLength)
     The maximum number of terms that will be indexed for a single field in a document.
public  voidsetMergeFactor(int mergeFactor)
     Determines how often segment indices are merged by addDocument().
public  voidsetUseCompoundFile(boolean useCompoundFile)
     Setting to turn on usage of a compound file.
public  StringtoString()
    

Field Detail
analyzer
protected Analyzer analyzer(Code)



directory
protected Directory directory(Code)



indexReader
protected IndexReader indexReader(Code)



indexWriter
protected IndexWriter indexWriter(Code)



infoStream
protected PrintStream infoStream(Code)



maxBufferedDocs
protected int maxBufferedDocs(Code)



maxFieldLength
protected int maxFieldLength(Code)



mergeFactor
protected int mergeFactor(Code)



open
protected boolean open(Code)



useCompoundFile
protected boolean useCompoundFile(Code)




Constructor Detail
IndexModifier
public IndexModifier(Directory directory, Analyzer analyzer, boolean create) throws CorruptIndexException, LockObtainFailedException, IOException(Code)
Open an index with write access.
Parameters:
  directory - the index directory
Parameters:
  analyzer - the analyzer to use for adding new documents
Parameters:
  create - true to create the index or overwrite the existing one;false to append to the existing index
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IOException - if there is a low-level IO error



IndexModifier
public IndexModifier(String dirName, Analyzer analyzer, boolean create) throws CorruptIndexException, LockObtainFailedException, IOException(Code)
Open an index with write access.
Parameters:
  dirName - the index directory
Parameters:
  analyzer - the analyzer to use for adding new documents
Parameters:
  create - true to create the index or overwrite the existing one;false to append to the existing index
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IOException - if there is a low-level IO error



IndexModifier
public IndexModifier(File file, Analyzer analyzer, boolean create) throws CorruptIndexException, LockObtainFailedException, IOException(Code)
Open an index with write access.
Parameters:
  file - the index directory
Parameters:
  analyzer - the analyzer to use for adding new documents
Parameters:
  create - true to create the index or overwrite the existing one;false to append to the existing index
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IOException - if there is a low-level IO error




Method Detail
addDocument
public void addDocument(Document doc, Analyzer docAnalyzer) throws CorruptIndexException, LockObtainFailedException, IOException(Code)
Adds a document to this index, using the provided analyzer instead of the one specific in the constructor. If the document contains more than IndexModifier.setMaxFieldLength(int) terms for a given field, the remainder are discarded.
See Also:   IndexWriter.addDocument(DocumentAnalyzer)
throws:
  IllegalStateException - if the index is closed
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IOException - if there is a low-level IO error



addDocument
public void addDocument(Document doc) throws CorruptIndexException, LockObtainFailedException, IOException(Code)
Adds a document to this index. If the document contains more than IndexModifier.setMaxFieldLength(int) terms for a given field, the remainder are discarded.
See Also:   IndexWriter.addDocument(Document)
throws:
  IllegalStateException - if the index is closed
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IOException - if there is a low-level IO error



assureOpen
protected void assureOpen()(Code)
Throw an IllegalStateException if the index is closed.
throws:
  IllegalStateException -



close
public void close() throws CorruptIndexException, IOException(Code)
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



createIndexReader
protected void createIndexReader() throws CorruptIndexException, IOException(Code)
Close the IndexWriter and open an IndexReader.
throws:
  CorruptIndexException - if the index is corrupt
throws:
  IOException - if there is a low-level IO error



createIndexWriter
protected void createIndexWriter() throws CorruptIndexException, LockObtainFailedException, IOException(Code)
Close the IndexReader and open an IndexWriter.
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IOException - if there is a low-level IO error



deleteDocument
public void deleteDocument(int docNum) throws StaleReaderException, CorruptIndexException, LockObtainFailedException, IOException(Code)
Deletes the document numbered docNum.
See Also:   IndexReader.deleteDocument(int)
throws:
  StaleReaderException - if the index has changedsince this reader was opened
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IllegalStateException - if the index is closed



deleteDocuments
public int deleteDocuments(Term term) throws StaleReaderException, CorruptIndexException, LockObtainFailedException, IOException(Code)
Deletes all documents containing term. This is useful if one uses a document field to hold a unique ID string for the document. Then to delete such a document, one merely constructs a term with the appropriate field and the unique ID string as its text and passes it to this method. Returns the number of documents deleted. the number of documents deleted
See Also:   IndexReader.deleteDocuments(Term)
throws:
  IllegalStateException - if the index is closed
throws:
  StaleReaderException - if the index has changedsince this reader was opened
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IOException - if there is a low-level IO error



docCount
public int docCount()(Code)
Returns the number of documents currently in this index.
See Also:   IndexWriter.docCount
See Also:   IndexReader.numDocs
throws:
  IllegalStateException - if the index is closed



flush
public void flush() throws CorruptIndexException, LockObtainFailedException, IOException(Code)
Make sure all changes are written to disk.
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IOException - if there is a low-level IO error



getInfoStream
public PrintStream getInfoStream() throws CorruptIndexException, LockObtainFailedException, IOException(Code)

See Also:   IndexModifier.setInfoStream(PrintStream)
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IOException - if there is a low-level IO error



getMaxBufferedDocs
public int getMaxBufferedDocs() throws CorruptIndexException, LockObtainFailedException, IOException(Code)

See Also:   IndexModifier.setMaxBufferedDocs(int)
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IOException - if there is a low-level IO error



getMaxFieldLength
public int getMaxFieldLength() throws CorruptIndexException, LockObtainFailedException, IOException(Code)

See Also:   IndexModifier.setMaxFieldLength(int)
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IOException - if there is a low-level IO error



getMergeFactor
public int getMergeFactor() throws CorruptIndexException, LockObtainFailedException, IOException(Code)

See Also:   IndexModifier.setMergeFactor(int)
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IOException - if there is a low-level IO error



getUseCompoundFile
public boolean getUseCompoundFile() throws CorruptIndexException, LockObtainFailedException, IOException(Code)

See Also:   IndexModifier.setUseCompoundFile(boolean)
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IOException - if there is a low-level IO error



init
protected void init(Directory directory, Analyzer analyzer, boolean create) throws CorruptIndexException, LockObtainFailedException, IOException(Code)
Initialize an IndexWriter.
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IOException - if there is a low-level IO error



optimize
public void optimize() throws CorruptIndexException, LockObtainFailedException, IOException(Code)
Merges all segments together into a single segment, optimizing an index for search.
See Also:   IndexWriter.optimize
throws:
  IllegalStateException - if the index is closed
throws:
  CorruptIndexException - if the index is corrupt
throws:
  LockObtainFailedException - if another writerhas this index open (write.lock could notbe obtained)
throws:
  IOException - if there is a low-level IO error



setInfoStream
public void setInfoStream(PrintStream infoStream)(Code)
If non-null, information about merges and a message when IndexModifier.getMaxFieldLength() is reached will be printed to this.

Example: index.setInfoStream(System.err);
See Also:   IndexWriter.setInfoStream(PrintStream)
throws:
  IllegalStateException - if the index is closed




setMaxBufferedDocs
public void setMaxBufferedDocs(int maxBufferedDocs)(Code)
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 org.apache.lucene.store.RAMDirectory , large value gives faster indexing. At the same time, mergeFactor limits the number of files open in a FSDirectory.

The default value is 10.
See Also:   IndexWriter.setMaxBufferedDocs(int)
throws:
  IllegalStateException - if the index is closed
throws:
  IllegalArgumentException - if maxBufferedDocs is smaller than 2




setMaxFieldLength
public void setMaxFieldLength(int maxFieldLength)(Code)
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.

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.

By default, no more than 10,000 terms will be indexed for a field.
See Also:   IndexWriter.setMaxFieldLength(int)
throws:
  IllegalStateException - if the index is closed




setMergeFactor
public void setMergeFactor(int mergeFactor)(Code)
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 (> 10) are best for batch index creation, and smaller values (< 10) for indices that are interactively maintained.

This must never be less than 2. The default value is 10.
See Also:   IndexWriter.setMergeFactor(int)
throws:
  IllegalStateException - if the index is closed




setUseCompoundFile
public void setUseCompoundFile(boolean useCompoundFile)(Code)
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 Also:   IndexWriter.setUseCompoundFile(boolean)
throws:
  IllegalStateException - if the index is closed



toString
public String toString()(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.