use of org.geotoolkit.index.IndexingException in project geotoolkit by Geomatys.
the class LuceneIndexSearcher method refresh.
/**
* Refresh the searcher (must be call after deleting document from the index for example)
*
* @throws IndexingException
*/
public void refresh() throws IndexingException {
try {
initSearcher();
initIdentifiersList();
cachedQueries.clear();
LOGGER.log(logLevel, "refreshing index searcher");
} catch (CorruptIndexException ex) {
throw new IndexingException("Corruption exception encountered during refreshing the index searcher", ex);
} catch (IOException ex) {
throw new IndexingException("IO Exception during refreshing the index searcher", ex);
}
}
use of org.geotoolkit.index.IndexingException in project geotoolkit by Geomatys.
the class AbstractIndexer method indexDocument.
/**
* This method add to index of lucene a new document.
*
* @param meta The object to index.
*/
public void indexDocument(final E meta) {
final IndexWriterConfig config = new IndexWriterConfig(analyzer);
try (final IndexWriter writer = new IndexWriter(LuceneUtils.getAppropriateDirectory(getFileDirectory()), config)) {
final int docId = writer.getDocStats().maxDoc;
// adding the document in a specific model. in this case we use a MDwebDocument.
writer.addDocument(createDocument(meta, docId));
LOGGER.log(Level.FINER, "Metadata: {0} indexed", getIdentifier(meta));
if (rTree != null) {
rTree.getTreeElementMapper().flush();
rTree.flush();
}
} catch (IndexingException | StoreIndexException ex) {
LOGGER.log(Level.WARNING, "Error while indexing single document", ex);
} catch (IOException ex) {
LOGGER.log(Level.WARNING, IO_SINGLE_MSG + ex.getMessage(), ex);
}
}
use of org.geotoolkit.index.IndexingException in project geotoolkit by Geomatys.
the class AbstractIndexer method indexDocument.
/**
* Index a document from the specified object with the specified index writer.
* Used when indexing in line many document.
*
* @param writer An Lucene index writer.
* @param meta The object to index.
*/
protected void indexDocument(final IndexWriter writer, final E meta) throws IndexingException {
try {
if (meta != null) {
final int docId = writer.getDocStats().maxDoc;
// adding the document in a specific model. in this case we use a MDwebDocument.
writer.addDocument(createDocument(meta, docId));
LOGGER.log(Level.FINER, "Metadata: {0} indexed", getIdentifier(meta));
}
} catch (IOException ex) {
throw new IndexingException("Error while writing document into index", ex);
}
}
use of org.geotoolkit.index.IndexingException in project geotoolkit by Geomatys.
the class AbstractIndexer method createIndex.
/**
* Create a new Index.
*
* @throws IndexingException
*/
public void createIndex() throws IndexingException {
LOGGER.log(logLevel, "(light memory) Creating lucene index please wait...");
final long time = System.currentTimeMillis();
int nbEntries = 0;
final IndexWriterConfig conf = new IndexWriterConfig(analyzer);
final String serviceID = getServiceID();
try (final IndexWriter writer = new IndexWriter(LuceneUtils.getAppropriateDirectory(getFileDirectory()), conf)) {
resetTree();
LOGGER.log(logLevel, "starting indexing...");
if (useEntryIterator()) {
final Iterator<E> entries = getEntryIterator();
while (entries.hasNext()) {
if (!stopIndexing && !indexationToStop.contains(serviceID)) {
try {
final E entry = entries.next();
indexDocument(writer, entry);
} catch (IndexingException ex) {
LOGGER.warning("Error while indexing document. moving to next.");
}
nbEntries++;
} else {
LOGGER.info("Index creation stopped after " + (System.currentTimeMillis() - time) + " ms for service:" + serviceID);
stopIndexation(serviceID);
return;
}
}
if (entries instanceof CloseableIterator) {
((CloseableIterator) entries).close();
}
} else {
final Iterator<String> identifiers = getIdentifierIterator();
while (identifiers.hasNext()) {
final String identifier = identifiers.next();
if (!stopIndexing && !indexationToStop.contains(serviceID)) {
try {
final E entry = getEntry(identifier);
indexDocument(writer, entry);
nbEntries++;
} catch (IndexingException ex) {
LOGGER.log(Level.WARNING, "Metadata IO exeption while indexing metadata: " + identifier + " " + ex.getMessage() + "\nmove to next metadata...", ex);
}
} else {
LOGGER.info("Index creation stopped after " + (System.currentTimeMillis() - time) + " ms for service:" + serviceID);
stopIndexation(serviceID);
return;
}
}
if (identifiers instanceof CloseableIterator) {
((CloseableIterator) identifiers).close();
}
}
// we store the numeric fields in a properties file int the index directory
storeNumericFieldsFile();
} catch (IOException | StoreIndexException | SQLException ex) {
LOGGER.log(Level.SEVERE, IO_SINGLE_MSG + "{0}", ex.getMessage());
throw new IndexingException("IOException while indexing documents:" + ex.getMessage(), ex);
}
LOGGER.log(logLevel, "Index creation process in " + (System.currentTimeMillis() - time) + " ms\n documents indexed: " + nbEntries + ".");
}
Aggregations