|
Regain 2.1.0-STABLE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.regain.crawler.IndexWriterManager
public class IndexWriterManager
Kontrolliert und kapselt die Erstellung des Suchindex.
Anwendung:
Rufen Sie für jedes Dokument addToIndex(RawDocument, ErrorLogger)
auf. Rufen Sie am Ende close(boolean)
auf, um den Index zu
schlie�en. Danach sind keine weiteren Aufrufe von
addToIndex(RawDocument, ErrorLogger)
erlaubt.
Field Summary | |
---|---|
private static int |
ALL_CLOSED_MODE
The all closed mode. |
private static String |
BREAKPOINT_INDEX_SUBDIR
The name of the index sub directory that contains a breakpoint. |
private Profiler |
mAddToIndexProfiler
Der Profiler der das Hinzufügen zum Index mißt. |
private File |
mAnalysisDir
Das Verzeichnis, in dem die Analyse-Dateien erstellt werden soll. |
private org.apache.lucene.analysis.Analyzer |
mAnalyzer
Der Analyzer, der vom IndexWriter genutzt werden soll. |
private File |
mBreakpointIndexDir
The directory to create breakpoint indices. |
private Profiler |
mBreakpointProfiler
The profiler for the breakpoint creation. |
private CrawlerConfig |
mConfig
The crawler configuration. |
private DocumentFactory |
mDocumentFactory
Die DocumentFactory, die die Inhalte für die Indizierung aufbereitet. |
private File |
mErrorLogFile
The file where the error log should be stored. |
private FileOutputStream |
mErrorLogStream
The stream used for writing errors to the error log of the index. |
private PrintWriter |
mErrorLogWriter
The print writer used for writing errors to the error log of the index. |
private org.apache.lucene.index.IndexReader |
mIndexReader
Der gekapselte IndexReader. |
private org.apache.lucene.search.IndexSearcher |
mIndexSearcher
Der gekapselte IndexSearcher. |
private org.apache.lucene.index.IndexWriter |
mIndexWriter
Der gekapselte IndexWriter, der den eigentlichen Index erstellt. |
private int |
mInitialDocCount
The number of documents that were in the (old) index when the IndexWriterManager was created. |
private static org.apache.log4j.Logger |
mLog
The logger for this class |
private org.apache.lucene.store.Directory |
mLuceneTempIndexDir
The lucene representation of mTempIndexDir. |
private File |
mNewIndexDir
Das Verzeichnis, in dem der Suchindex am Ende stehen soll, wenn es keine fatalen Fehler gab. |
private File |
mQuarantineIndexDir
Das Verzeichnis, in dem der Suchindex am Ende stehen soll, wenn es fatale Fehler gab. |
private boolean |
mRetryFailedDocs
Specifies whether a document that couldn't be prepared the last time should be retried. |
private File |
mTempIndexDir
Das Verzeichnis, in dem der neue Suchindex aufgebaut werden soll. |
private boolean |
mUpdateIndex
Gibt an, ob ein bestehender Index aktualisiert wird. |
private HashMap<String,String> |
mUrlsToDeleteHash
enthält die URL und den LastUpdated-String aller Dokumente, deren Eintr�ge beim Abschlie�en des Index entfernt werden m�ssen. |
private static String |
NEW_INDEX_SUBDIR
Der Name des Index-Unterverzeichnisses, in das der neue Index gestellt werden soll, sobald er fertig ist ohne dass fatale Fehler aufgetreten sind. |
private CrawlerPluginManager |
pluginManager
Crawler Plugin Manager instance |
private static String |
QUARANTINE_INDEX_SUBDIR
Der Name des Index-Unterverzeichnisses, in das der neue Index gestellt werden soll, sobald er fertig ist, wobei fatale Fehler sufgetreten sind. |
private static int |
READING_MODE
The reading mode. |
private static long |
RENAME_TIMEOUT
Workaround: Unter Windows klappt das Umbenennen unmittelbar nach Schlie�en des Index nicht. |
private static int |
SEARCHING_MODE
The searching mode. |
private static String |
TEMP_INDEX_SUBDIR
Der Name des Index-Unterverzeichnisses, in dem der neue Index aufgebaut werden soll. |
private static String |
WORKING_INDEX_SUBDIR
Der Name des Index-Unterverzeichnisses, in dem der genutzte Index steht. |
private static boolean |
WRITE_TERMS_SORTED
Gibt an, ob die Terme sortiert in die Terme-Datei geschrieben werden soll. |
private static int |
WRITING_MODE
The writing mode. |
Constructor Summary | |
---|---|
IndexWriterManager(CrawlerConfig config,
boolean updateIndex,
boolean retryFailedDocs)
Erzeugt eine neue IndexWriterManager-Instanz. |
Method Summary | |
---|---|
void |
addToIndex(RawDocument rawDocument,
ErrorLogger errorLogger)
Adds a document to an index. |
void |
close(boolean putIntoQuarantine)
Optimiert und schlie�t den Index |
private boolean |
copyExistingIndex(File indexDir,
String analyzerType)
Kopiert den zuletzt erstellten Index in das Arbeitsverzeichnis. |
void |
createBreakpoint()
Creates a breakpoint. |
private org.apache.lucene.index.IndexWriter |
createIndexWriter(boolean createNewIndex)
|
void |
createNewIndexEntry(RawDocument rawDocument,
ErrorLogger errorLogger)
Creates a indexable document and add this to the index |
private void |
deleteOldIndex(File oldIndexDir)
Delets an old index directory. |
int |
getAddedDocCount()
Gets the number of documents that were added to the index. |
DocumentFactory |
getDocumentFactory()
Getter for the current and initialised DocumentFactory. |
int |
getIndexEntryCount()
Gibt die Anzahl der Eintr�ge im Index zurück. |
int |
getInitialDocCount()
Gets the number of documents that were in the (old) index when the IndexWriterManager was created. |
int |
getRemovedDocCount()
Gets the number of documents that will be removed from the index. |
boolean |
getUpdateIndex()
Gibt zurück, ob ein bestehender Index aktualisiert wird. |
boolean |
isAlreadyIndexed(String url)
Lookup for a document matching to a given url. |
private boolean |
isMarkedForDeletion(org.apache.lucene.document.Document doc)
Gibt zurück, ob ein Dokument für die Löschung vorgemerkt wurde. |
void |
logError(String msg,
Throwable thr)
Logs an error at the error log of the index. |
private void |
markForDeletion(org.apache.lucene.document.Document doc)
Merkt ein Dokument für die sp�tere L�schung vor. |
void |
parseDocument(RawDocument rawDocument,
ErrorLogger errorLogger)
Creates a document but don't add this to the index |
private void |
prepareBreakpoint()
Prepares a breakpoint. |
private void |
removeObsoleteEntries()
Goes through the index and deletes all obsolete entries. |
void |
removeObsoleteEntries(UrlChecker urlChecker)
Goes through the index and deletes all obsolete entries. |
private void |
setIndexMode(int mode)
Sets the current mode The are the following modes: Writing mode: The mIndexWriter is opened, the mIndexSearcher may be opened, the mIndexReader is closed. |
private void |
writeTermFile(File indexDir,
File termFile)
Erzeugt eine Datei, die alle Terme (also alle erlaubten Suchtexte) enthält. |
private int |
writeTermsSimply(org.apache.lucene.index.TermEnum termEnum,
PrintWriter writer)
Schreibt die Terme so wie sie vom IndexReader kommen in den Writer. |
private int |
writeTermsSorted(org.apache.lucene.index.TermEnum termEnum,
PrintWriter writer)
Schreibt die Terme vom IndexReader sortiert in den Writer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static org.apache.log4j.Logger mLog
private static final String NEW_INDEX_SUBDIR
Die Suchmaske wird, sobald es diese Verzeichnis gibt seine Suche darauf umstellen. Dabei wird es in "index" umbenannt.
private static final String QUARANTINE_INDEX_SUBDIR
private static final String WORKING_INDEX_SUBDIR
private static final String TEMP_INDEX_SUBDIR
private static final String BREAKPOINT_INDEX_SUBDIR
NOTE: The crawler creates periodically so called breakpoints. If the crawler should be stopped before it is finished it can use a breakpoint to go on the next time. Besides the search mask can use a breakpoint if no other index exists. So the user can already search before the first index was fully created.
private static final boolean WRITE_TERMS_SORTED
writeTermFile(File, File)
,
Constant Field Valuesprivate static final long RENAME_TIMEOUT
private static final int WRITING_MODE
setIndexMode(int)
,
Constant Field Valuesprivate static final int READING_MODE
setIndexMode(int)
,
Constant Field Valuesprivate static final int SEARCHING_MODE
setIndexMode(int)
,
Constant Field Valuesprivate static final int ALL_CLOSED_MODE
setIndexMode(int)
,
Constant Field Valuesprivate CrawlerConfig mConfig
private org.apache.lucene.analysis.Analyzer mAnalyzer
private org.apache.lucene.index.IndexWriter mIndexWriter
private org.apache.lucene.index.IndexReader mIndexReader
Ist null
, wenn der Index nicht aktualisiert werden soll.
private org.apache.lucene.search.IndexSearcher mIndexSearcher
Ist null
, wenn der Index nicht aktualisiert werden soll.
private boolean mUpdateIndex
Anderenfalls wird ein komplett neuer Index angelegt.
private boolean mRetryFailedDocs
private DocumentFactory mDocumentFactory
private File mNewIndexDir
private File mQuarantineIndexDir
private File mTempIndexDir
private org.apache.lucene.store.Directory mLuceneTempIndexDir
private File mBreakpointIndexDir
private File mAnalysisDir
private File mErrorLogFile
private FileOutputStream mErrorLogStream
null
.
private PrintWriter mErrorLogWriter
null
.
private int mInitialDocCount
private Profiler mAddToIndexProfiler
private Profiler mBreakpointProfiler
private HashMap<String,String> mUrlsToDeleteHash
Die URL bildet den key, der LastUpdated-String die value.
private CrawlerPluginManager pluginManager
Constructor Detail |
---|
public IndexWriterManager(CrawlerConfig config, boolean updateIndex, boolean retryFailedDocs) throws RegainException
config
- Die zu verwendende Konfiguration.updateIndex
- Gibt an, ob ein bereits bestehender Index aktualisiert
werden soll.retryFailedDocs
- Specifies whether a document that couldn't be
prepared the last time should be retried.
RegainException
- Wenn der neue Index nicht vorbereitet werden konnte.Method Detail |
---|
public boolean getUpdateIndex()
Anderenfalls wird ein komplett neuer Index angelegt.
public int getInitialDocCount()
public int getAddedDocCount()
public int getRemovedDocCount()
public void logError(String msg, Throwable thr) throws RegainException
msg
- The error message.thr
- The error to log. May be null
.
RegainException
- If writing to the error log failed.private void setIndexMode(int mode) throws RegainException
The are the following modes:
If the index already is in the wanted mode nothing happens. This method is very fast in this case.
mode
- The mode the index should have. Must be one of
WRITING_MODE
, READING_MODE
, SEARCHING_MODE
or ALL_CLOSED_MODE
.
RegainException
- If closing or opening failed.private org.apache.lucene.index.IndexWriter createIndexWriter(boolean createNewIndex) throws IOException
IOException
private boolean copyExistingIndex(File indexDir, String analyzerType) throws RegainException
indexDir
- Das Verzeichnis, in dem der Index liegt.analyzerType
- Der Analyzer-Typ, den der alte Index haben muss, um
übernommen zu werden.
RegainException
- Wenn das Kopieren fehl schlug.public boolean isAlreadyIndexed(String url) throws RegainException
url
- to check for
RegainException
- if checking for url failedpublic void addToIndex(RawDocument rawDocument, ErrorLogger errorLogger) throws RegainException
rawDocument
- the document to add to a indexerrorLogger
- The error logger to use for logging errors.
RegainException
- if adding of the document failedpublic void createNewIndexEntry(RawDocument rawDocument, ErrorLogger errorLogger) throws RegainException
rawDocument
- which will be parsederrorLogger
- The error logger to use for logging errors.
RegainException
- if indexing of the document failedpublic void parseDocument(RawDocument rawDocument, ErrorLogger errorLogger) throws RegainException
rawDocument
- which will be parsederrorLogger
- The error logger to use for logging errors.
RegainException
- if parsing of the document failedpublic DocumentFactory getDocumentFactory()
public void removeObsoleteEntries(UrlChecker urlChecker) throws RegainException
Entries are obsolete if they are marked for deletion by the
IndexWriterManager (see mUrlsToDeleteHash
) or if the don't neither
match an entry of the urlToKeepSet nor of the prefixesToKeepArr.
urlChecker
- The UrlChecker to use for deciding whether an index entry
should be kept in the index or not. If null only the documents in
the mUrlsToDeleteHash
will be deleted.
RegainException
- If an index entry could either not be read or
deleted.private void removeObsoleteEntries() throws RegainException
Entries are obsolete if they are marked for deletion by the
IndexWriterManager (see mUrlsToDeleteHash
).
RegainException
- If an index entry could either not be read or
deleted.private void markForDeletion(org.apache.lucene.document.Document doc)
Diese Methode ist Teil eines Workaround: Ein alter Eintrag, der durch einen neuen ersetzt wird, wird nicht sofort gel�scht, sondern nur zur L�schung vorgemerkt. Auf diese Weise wird ein seltener Fehler umgangen, der das Schlie�en des IndexWriter verhindert, wenn h�ufig zwischen InderWriter und IndexReader gewechselt wird.
doc
- Das vorzumerkende Dokument.private boolean isMarkedForDeletion(org.apache.lucene.document.Document doc)
doc
- Das zu prüfende Dokument.
public int getIndexEntryCount() throws RegainException
RegainException
- Wenn die Anzahl nicht ermittelt werden konnte.private void prepareBreakpoint() throws RegainException
RegainException
- If preparing the breakpoint failed.public void createBreakpoint() throws RegainException
RegainException
- If creating the breakpoint failed.public void close(boolean putIntoQuarantine) throws RegainException
putIntoQuarantine
- Gibt an, ob der Index in Quarant�ne soll.
RegainException
- Wenn der Index nicht geschlossen werden konnte.private void deleteOldIndex(File oldIndexDir) throws RegainException
oldIndexDir
- The old index directory.
RegainException
- If deleting failed.private void writeTermFile(File indexDir, File termFile) throws RegainException
indexDir
- Das Verzeichnis, in dem der Index steht.termFile
- Der Ort, wo die Datei erstellt werden soll.
RegainException
- Wenn die Erstellung fehlgeschlagen ist.private int writeTermsSimply(org.apache.lucene.index.TermEnum termEnum, PrintWriter writer) throws IOException
Diese Methode braucht minimale Ressourcen.
termEnum
- Die Aufz�hlung mit allen Termen.writer
- Der Writer auf den geschrieben werden soll.
IOException
- Wenn das Schreiben fehl schlug.private int writeTermsSorted(org.apache.lucene.index.TermEnum termEnum, PrintWriter writer) throws IOException
Um die Terme sortieren zu können, m�ssen sie zwischengespeichert werden. Falls es zu viele sind, k�nnte das schief gehen. In diesem Fall sollte man auf simples Schreiben umstellen.
termEnum
- Die Aufz�hlung mit allen Termen.writer
- Der Writer auf den geschrieben werden soll.
IOException
- Wenn das Schreiben fehl schlug.
|
Regain 2.1.0-STABLE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |