com.impetus.kundera.index
Class LuceneIndexer

java.lang.Object
  extended by com.impetus.kundera.index.DocumentIndexer
      extended by com.impetus.kundera.index.LuceneIndexer
All Implemented Interfaces:
Indexer

public class LuceneIndexer
extends DocumentIndexer

Provides indexing functionality using lucene library.

Author:
amresh.singh

Field Summary
private static org.apache.lucene.store.Directory index
          The index.
private static LuceneIndexer indexer
          The indexer.
private static boolean isInitialized
          The is initialized.
private static org.slf4j.Logger log
          log for this class.
private static String luceneDirPath
          The lucene dir path.
private static org.apache.lucene.index.IndexReader reader
          The reader.
private static boolean readyForCommit
          The ready for commit.
private static org.apache.lucene.index.IndexWriter w
          The w.
 
Fields inherited from class com.impetus.kundera.index.DocumentIndexer
analyzer, DEFAULT_SEARCHABLE_FIELD, docNumber, INDEX_NAME, SUPERCOLUMN_INDEX, tokenizer
 
Constructor Summary
private LuceneIndexer(String lucDirPath)
          Instantiates a new lucene indexer.
 
Method Summary
 void close()
          Close of transaction.
private  void copy(org.apache.lucene.store.Directory src, org.apache.lucene.store.Directory to)
           
 boolean documentExistsInIndex(EntityMetadata metadata, Object id)
           
 boolean entityExistsInIndex(Class<?> entityClass)
           
 void flush()
           
private  void flushInternal()
          Flush internal.
private  File getIndexDirectory()
          Creates a Lucene index directory if it does not exist.
private  org.apache.lucene.index.IndexReader getIndexReader()
          Returns default index reader.
private  org.apache.lucene.index.IndexWriter getIndexWriter()
          Added for HBase support.
static LuceneIndexer getInstance(String lucDirPath)
          Gets the single instance of LuceneIndexer.
 void index(Class entityClazz, Map<String,Object> values, Object parentId, Class parentClazz)
           
 void index(EntityMetadata metadata, Object object)
           
 void index(EntityMetadata metadata, Object object, String parentId, Class<?> clazz)
           
 void indexDocument(EntityMetadata metadata, org.apache.lucene.document.Document document)
          Indexes document in file system using lucene.
private  org.apache.lucene.document.Document indexDocument(EntityMetadata metadata, Object object, String parentId, Class<?> clazz)
          Index document.
private  void onCommit()
          On commit.
 Map<String,Object> search(Class<?> clazz, String luceneQuery, int start, int end)
           
 Map<String,Object> search(String luceneQuery, int start, int count, boolean fetchRelation)
           
 void unIndex(Class entityClazz, Object entity)
           
 void unindex(EntityMetadata metadata, Object id)
           
 void update(EntityMetadata metadata, Object entity, Object id, String parentId)
           
private  void updateDocument(EntityMetadata metadata, Object entity, String parentId, Class<? extends Object> class1, boolean b)
          Updates document.
 void updateDocument(String id, org.apache.lucene.document.Document document)
          Indexes document in file system using lucene.
private  org.apache.lucene.document.Document updateOrIndexDocument(EntityMetadata metadata, Object entity, String parentId, Class<?> clazz, boolean isUpdate)
          Update/Index document.
 
Methods inherited from class com.impetus.kundera.index.DocumentIndexer
addEntityClassToDocument, addEntityFieldsToDocument, addParentKeyToDocument, createSuperColumnDocument, getCannonicalPropertyName, getKunderaId, indexSuperColumn, prepareDocumentForSuperColumn, search
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.slf4j.Logger log
log for this class.


w

private static org.apache.lucene.index.IndexWriter w
The w.


reader

private static org.apache.lucene.index.IndexReader reader
The reader.


index

private static org.apache.lucene.store.Directory index
The index.


isInitialized

private static boolean isInitialized
The is initialized.


indexer

private static LuceneIndexer indexer
The indexer.


readyForCommit

private static boolean readyForCommit
The ready for commit.


luceneDirPath

private static String luceneDirPath
The lucene dir path.

Constructor Detail

LuceneIndexer

private LuceneIndexer(String lucDirPath)
Instantiates a new lucene indexer.

Parameters:
analyzer - the analyzer
lucDirPath - the luc dir path
Method Detail

getInstance

public static LuceneIndexer getInstance(String lucDirPath)
Gets the single instance of LuceneIndexer.

Parameters:
analyzer - the analyzer
lucDirPath - the luc dir path
Returns:
single instance of LuceneIndexer

getIndexWriter

private org.apache.lucene.index.IndexWriter getIndexWriter()
Added for HBase support.

Returns:
default index writer

getIndexReader

private org.apache.lucene.index.IndexReader getIndexReader()
Returns default index reader.

Returns:
index reader.

getIndexDirectory

private File getIndexDirectory()
Creates a Lucene index directory if it does not exist.

Returns:
the index directory

index

public final void index(EntityMetadata metadata,
                        Object object)

unindex

public final void unindex(EntityMetadata metadata,
                          Object id)
                   throws LuceneIndexingException
Throws:
LuceneIndexingException

update

public final void update(EntityMetadata metadata,
                         Object entity,
                         Object id,
                         String parentId)

search

public final Map<String,Object> search(String luceneQuery,
                                       int start,
                                       int count,
                                       boolean fetchRelation)

indexDocument

public void indexDocument(EntityMetadata metadata,
                          org.apache.lucene.document.Document document)
Indexes document in file system using lucene.

Specified by:
indexDocument in class DocumentIndexer
Parameters:
metadata - the metadata
document - the document

updateDocument

public void updateDocument(String id,
                           org.apache.lucene.document.Document document)
Indexes document in file system using lucene.

Parameters:
metadata - the metadata
document - the document

flushInternal

private void flushInternal()
Flush internal.


close

public void close()
Close of transaction.


flush

public void flush()

index

public void index(EntityMetadata metadata,
                  Object object,
                  String parentId,
                  Class<?> clazz)

entityExistsInIndex

public boolean entityExistsInIndex(Class<?> entityClass)

documentExistsInIndex

public boolean documentExistsInIndex(EntityMetadata metadata,
                                     Object id)

indexDocument

private org.apache.lucene.document.Document indexDocument(EntityMetadata metadata,
                                                          Object object,
                                                          String parentId,
                                                          Class<?> clazz)
Index document.

Parameters:
metadata - the metadata
object - the object
parentId - the parent id
clazz - the clazz
Returns:
the document

updateOrIndexDocument

private org.apache.lucene.document.Document updateOrIndexDocument(EntityMetadata metadata,
                                                                  Object entity,
                                                                  String parentId,
                                                                  Class<?> clazz,
                                                                  boolean isUpdate)
Update/Index document.

Parameters:
metadata - the metadata
entity - the object
parentId - the parent id
clazz - the clazz
Returns:
the document

onCommit

private void onCommit()
On commit.


index

public void index(Class entityClazz,
                  Map<String,Object> values,
                  Object parentId,
                  Class parentClazz)

unIndex

public void unIndex(Class entityClazz,
                    Object entity)

search

public Map<String,Object> search(Class<?> clazz,
                                 String luceneQuery,
                                 int start,
                                 int end)

copy

private void copy(org.apache.lucene.store.Directory src,
                  org.apache.lucene.store.Directory to)
           throws IOException
Throws:
IOException

updateDocument

private void updateDocument(EntityMetadata metadata,
                            Object entity,
                            String parentId,
                            Class<? extends Object> class1,
                            boolean b)
Updates document.

Parameters:
metadata - the metadata
entity - the object
parentId - the parent id
clazz - the clazz


Copyright © 2014. All Rights Reserved.