Search in sources :

Example 1 with IndexingException

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);
    }
}
Also used : IndexingException(org.geotoolkit.index.IndexingException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) IOException(java.io.IOException)

Example 2 with IndexingException

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);
    }
}
Also used : StoreIndexException(org.geotoolkit.index.tree.StoreIndexException) IndexingException(org.geotoolkit.index.IndexingException) IndexWriter(org.apache.lucene.index.IndexWriter) IOException(java.io.IOException) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 3 with IndexingException

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);
    }
}
Also used : IndexingException(org.geotoolkit.index.IndexingException) IOException(java.io.IOException)

Example 4 with IndexingException

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 + ".");
}
Also used : StoreIndexException(org.geotoolkit.index.tree.StoreIndexException) CloseableIterator(org.geotoolkit.util.collection.CloseableIterator) SQLException(java.sql.SQLException) IOException(java.io.IOException) IndexingException(org.geotoolkit.index.IndexingException) IndexWriter(org.apache.lucene.index.IndexWriter) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Aggregations

IOException (java.io.IOException)4 IndexingException (org.geotoolkit.index.IndexingException)4 IndexWriter (org.apache.lucene.index.IndexWriter)2 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)2 StoreIndexException (org.geotoolkit.index.tree.StoreIndexException)2 SQLException (java.sql.SQLException)1 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)1 CloseableIterator (org.geotoolkit.util.collection.CloseableIterator)1