Package org.apache.lucene.index

Examples of org.apache.lucene.index.IndexModifier


        // If we're currently rebuilding the index, return.
        if (rebuildInProgress) {
            return;
        }
        writerLock.lock();
        IndexModifier writer = null;
        try {
            writer = new IndexModifier(directory, new StandardAnalyzer(), false);
            List<Long> conversationIDs = new ArrayList<Long>();
            Connection con = null;
            PreparedStatement pstmt = null;
            ResultSet rs = null;
            try {
                con = DbConnectionManager.getConnection();
                pstmt = con.prepareStatement(NEW_CONVERSATIONS);
                pstmt.setLong(1, lastModified);
                rs = pstmt.executeQuery();
                while (rs.next()) {
                    conversationIDs.add(rs.getLong(1));
                }
            }
            catch (SQLException sqle) {
                Log.error(sqle.getMessage(), sqle);
            }
            finally {
                DbConnectionManager.closeConnection(rs, pstmt, con);
            }

            // Delete any conversations found -- they may have already been indexed, but
            // updated since then.
            for (long conversationID : conversationIDs) {
                writer.deleteDocuments(new Term("conversationID", Long.toString(conversationID)));
            }

            // Load meta-data for each conversation.
            Map<Long, Boolean> externalMetaData = new HashMap<Long, Boolean>();
            for (long conversationID : conversationIDs) {
                try {
                    con = DbConnectionManager.getConnection();
                    pstmt = con.prepareStatement(CONVERSATION_METADATA);
                    pstmt.setLong(1, conversationID);
                    rs = pstmt.executeQuery();
                    while (rs.next()) {
                        externalMetaData.put(conversationID, rs.getInt(1) == 1);
                    }
                }
                catch (SQLException sqle) {
                    Log.error(sqle.getMessage(), sqle);
                }
                finally {
                    DbConnectionManager.closeConnection(rs, pstmt, con);
                }
            }

            // Now index all the new conversations.
            long newestDate = indexConversations(conversationIDs, externalMetaData, writer, false);

            writer.optimize();

            // Done indexing so store a last modified date.
            if (newestDate != -1) {
                lastModified = newestDate;
                indexProperties.setProperty("lastModified", Long.toString(lastModified));
            }
        }
        catch (IOException ioe) {
            Log.error(ioe.getMessage(), ioe);
        }
        finally {
            if (writer != null) {
                try {
                    writer.close();
                }
                catch (Exception e) {
                    Log.error(e.getMessage(), e);
                }
            }
View Full Code Here


                }

                if (!conversationIDs.isEmpty()) {
                    // Index the conversations.
                    writerLock.lock();
                    IndexModifier writer = null;
                    try {
                        writer = new IndexModifier(directory, new StandardAnalyzer(), true);
                        long newestDate = indexConversations(conversationIDs, externalMetaData,
                                writer, true);
                        writer.optimize();

                        // Done indexing so store a last modified date.
                        if (newestDate != -1) {
                            lastModified = newestDate;
                            indexProperties.setProperty("lastModified", Long.toString(lastModified));
                        }
                    }
                    catch (IOException ioe) {
                        Log.error(ioe.getMessage(), ioe);
                    }
                    finally {
                        if (writer != null) {
                            try {
                                writer.close();
                            }
                            catch (Exception e) {
                                Log.error(e.getMessage(), e);
                            }
                        }
View Full Code Here

            }
        }
    }

    public void testIndexWriterLockRelease() throws IOException {
        IndexModifier im;

        try {
            im = new IndexModifier(this.__test_dir, new org.apache.lucene.analysis.standard.StandardAnalyzer(), false);
        } catch (FileNotFoundException e) {
            try {
                im = new IndexModifier(this.__test_dir, new org.apache.lucene.analysis.standard.StandardAnalyzer(), false);
            } catch (FileNotFoundException e1) {
            }
        }
    }
View Full Code Here

    public void modifyRecords( Collection records )
        throws RepositoryIndexException
    {
        synchronized( repository )
        {
            IndexModifier indexModifier = null;
            try
            {
                indexModifier = new IndexModifier( indexLocation, indexHandlers.getAnalyzer(), !exists() );
                indexModifier.setMaxFieldLength( MAX_FIELD_LENGTH );
   
                for ( Iterator i = records.iterator(); i.hasNext(); )
                {
                    LuceneRepositoryContentRecord record = (LuceneRepositoryContentRecord) i.next();
   
                    if ( record != null )
                    {
                        Term term = new Term( LuceneDocumentMaker.PRIMARY_KEY, record.getPrimaryKey() );
   
                        indexModifier.deleteDocuments( term );
   
                        Document document = indexHandlers.getConverter().convert( record );
   
                        indexModifier.addDocument( document );
                    }
                }
                indexModifier.optimize();
            }
            catch ( IOException e )
            {
                throw new RepositoryIndexException( "Error updating index: " + e.getMessage(), e );
            }
View Full Code Here

    public void modifyRecord( LuceneRepositoryContentRecord record )
        throws RepositoryIndexException
    {
        synchronized( repository )
        {
            IndexModifier indexModifier = null;
            try
            {
                indexModifier = new IndexModifier( indexLocation, indexHandlers.getAnalyzer(), !exists() );
                indexModifier.setMaxFieldLength( MAX_FIELD_LENGTH );
   
                if ( record != null )
                {
                    Term term = new Term( LuceneDocumentMaker.PRIMARY_KEY, record.getPrimaryKey() );
   
                    indexModifier.deleteDocuments( term );
   
                    Document document = indexHandlers.getConverter().convert( record );
   
                    indexModifier.addDocument( document );
                }
                indexModifier.optimize();
            }
            catch ( IOException e )
            {
                throw new RepositoryIndexException( "Error updating index: " + e.getMessage(), e );
            }
View Full Code Here

    public void modifyRecords( Collection records )
        throws RepositoryIndexException
    {
        synchronized( repository )
        {
            IndexModifier indexModifier = null;
            try
            {
                indexModifier = new IndexModifier( indexLocation, indexHandlers.getAnalyzer(), !exists() );
                indexModifier.setMaxFieldLength( MAX_FIELD_LENGTH );
   
                for ( Iterator i = records.iterator(); i.hasNext(); )
                {
                    LuceneRepositoryContentRecord record = (LuceneRepositoryContentRecord) i.next();
   
                    if ( record != null )
                    {
                        Term term = new Term( LuceneDocumentMaker.PRIMARY_KEY, record.getPrimaryKey() );
   
                        indexModifier.deleteDocuments( term );
   
                        Document document = indexHandlers.getConverter().convert( record );
   
                        indexModifier.addDocument( document );
                    }
                }
                indexModifier.optimize();
            }
            catch ( IOException e )
            {
                throw new RepositoryIndexException( "Error updating index: " + e.getMessage(), e );
            }
View Full Code Here

    public void modifyRecord( LuceneRepositoryContentRecord record )
        throws RepositoryIndexException
    {
        synchronized( repository )
        {
            IndexModifier indexModifier = null;
            try
            {
                indexModifier = new IndexModifier( indexLocation, indexHandlers.getAnalyzer(), !exists() );
                indexModifier.setMaxFieldLength( MAX_FIELD_LENGTH );
   
                if ( record != null )
                {
                    Term term = new Term( LuceneDocumentMaker.PRIMARY_KEY, record.getPrimaryKey() );
   
                    indexModifier.deleteDocuments( term );
   
                    Document document = indexHandlers.getConverter().convert( record );
   
                    indexModifier.addDocument( document );
                }
                indexModifier.optimize();
            }
            catch ( IOException e )
            {
                throw new RepositoryIndexException( "Error updating index: " + e.getMessage(), e );
            }
View Full Code Here

*
*/
public class StorageModifierStub extends StorageModifier {
    public boolean throwException = false;
    public StorageModifierStub() throws IOException, StorageException{
        super(new StorageCoreControllerStub(), new IndexModifier(new RAMDirectory(),new StandardAnalyzer(),true), new StorageBuffer(1),1, 1);
    }
View Full Code Here

     */
    public StorageModifierStub(StorageCoreController controller,
            IndexModifier modifier, StorageBuffer buffer, int persitsFactor,
            int optimizeInterval) throws IOException, StorageException {
       
        super(new StorageCoreControllerStub(), new IndexModifier(new RAMDirectory(),new StandardAnalyzer(),true), new StorageBuffer(1),1, 1);
       
        // TODO Auto-generated constructor stub
    }
View Full Code Here

    }

    private StorageModifier createStorageModifier(boolean create)
            throws IOException {
        IndexModifier indexModifier = new IndexModifier(this.storageDir,
                new StandardAnalyzer(), create);
        return new StorageModifier(this, indexModifier, this.currentBuffer,
                this.storagePersistFactor, this.indexOptimizeInterval);
    }
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.IndexModifier

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.