Class LuceneIndex
Abstract object containing all of the logic used to use Lucene as an indexer
public class LuceneIndex : BaseIndexProvider, IIndex, IDisposable, IIndexStats, ReferenceManager.IRefreshListener
- Inheritance
-
Lucene
Index
- Implements
-
Reference
Manager .IRefreshListener
- Inherited Members
Constructors
LuceneIndex(ILoggerFactory, string, IOptionsMonitor<LuceneDirectoryIndexOptions>)
Constructor to create an indexer
public LuceneIndex(ILoggerFactory loggerFactory, string name, IOptionsMonitor<LuceneDirectoryIndexOptions> indexOptions)
Parameters
loggerFactory
ILoggerFactory name
stringindexOptions
IOptionsMonitor <LuceneDirectory >Index Options
LuceneIndex(ILoggerFactory, string, IOptionsMonitor<LuceneDirectoryIndexOptions>, Func<LuceneIndex, IIndexCommiter>, IndexWriter?)
Constructor
protected LuceneIndex(ILoggerFactory loggerFactory, string name, IOptionsMonitor<LuceneDirectoryIndexOptions> indexOptions, Func<LuceneIndex, IIndexCommiter> indexCommiterFactory, IndexWriter? writer = null)
Parameters
loggerFactory
ILoggerFactory name
stringindexOptions
IOptionsMonitor <LuceneDirectory >Index Options indexCommiterFactory
Func<LuceneIndex , IIndexCommiter >writer
IndexWriter
Exceptions
Properties
DefaultAnalyzer
The default analyzer to use when indexing content, by default, this is set to StandardAnalyzer
Property Value
- Analyzer
FieldAnalyzer
Gets the field ananlyzer
Property Value
- Per
Field Analyzer Wrapper
FieldValueTypeCollection
Returns the Field
Property Value
IndexWriter
Gets the TrackingIndexWriter for the current directory
Property Value
- Tracking
Index Writer
Remarks
Using a TrackingIndexWriter allows for more control over NRT readers. Though Examine doesn't specifically use the features of TrackingIndexWriter directly (i.e. to be able to wait for a specific generation), this is a requirement of NRT with SearchManager and ControlledRealTimeReopenThread. See example: http://www.lucenetutorial.com/lucene-nrt-hello-world.html http://blog.mikemccandless.com/2011/11/near-real-time-readers-with-lucenes.html https://stackoverflow.com/questions/17993960/lucene-4-4-0-new-controlledrealtimereopenthread-sample-usage TODO: Do we need/want to use the ControlledRealTimeReopenThread? Else according to mikecandles above in comments we can probably just get away with using MaybeReopen each time we search. Though there are comments in the lucene code to avoid that and do that on a background thread, which is exactly what ControlledRealTimeReopenThread already does.
RunAsync
Indicates whether or this system will process the queue items asynchonously - used for testing
Property Value
Searcher
Gets a searcher for the index
Property Value
TaxonomySearcher
Gets a Taxonomy searcher for the index
Property Value
TaxonomyWriter
Gets the taxonomy writer for the current index
Property Value
- Directory
Taxonomy Writer
Methods
AddDocument(Document, ValueSet)
Collects the data for the fields and adds the document which is then committed into Lucene.Net's index
Parameters
doc
DocumentvalueSet
ValueSet The data to index.
CreateFieldValueTypes(IReadOnlyDictionary<string, IFieldValueTypeFactory>?)
Creates the Field
protected virtual FieldValueTypeCollection CreateFieldValueTypes(IReadOnlyDictionary<string, IFieldValueTypeFactory>? indexValueTypesFactory = null)
Parameters
indexValueTypesFactory
IReadOnly <string, IFieldDictionary Value >Type Factory
Returns
CreateIndex()
Creates a new index, any existing index will be deleted
CreateIndexWriter(Directory?)
Method that creates the IndexWriter
Parameters
d
Directory
Returns
- Index
Writer
CreateTaxonomyWriter(Directory?)
Method that creates the IndexWriter
Parameters
d
Directory
Returns
- Directory
Taxonomy Writer
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Dispose(bool)
Parameters
disposing
bool
EnsureIndex(bool)
Creates a brand new index, this will override any existing index with an empty one
Parameters
forceOverwrite
bool
GetDocumentCount()
Gets the ammount of documents in the index
Returns
GetFieldNames()
Gets the field names in the index
Returns
GetLuceneDirectory()
Returns the Lucene Directory used to store the index
Returns
- Directory
GetLuceneTaxonomyDirectory()
Returns the Lucene Directory used to store the taxonomy index
Returns
- Directory
IndexExists()
Check if there is an index in the index folder
Returns
IndexReady()
Checks if the index is ready to open/write to.
Returns
IsReadable(out Exception?)
Check if the index is readable/healthy
Parameters
ex
Exception
Returns
OnDocumentWriting(DocumentWritingEventArgs)
Called when a document in writing
Parameters
docArgs
DocumentWriting Event Args
OnIndexingError(IndexingErrorEventArgs)
Called when an indexing error occurs
Parameters
PerformDeleteFromIndex(IEnumerable<string>, Action<IndexOperationEventArgs>)
Deletes a node from the index.
protected override void PerformDeleteFromIndex(IEnumerable<string> itemIds, Action<IndexOperationEventArgs> onComplete)
Parameters
itemIds
IEnumerable<string>ID of the node to delete
onComplete
Action<IndexOperation >Event Args
Remarks
When a content node is deleted, we also need to delete it's children from the index so we need to perform a custom Lucene search to find all decendents and create Delete item queues for them too.
PerformIndexItems(IEnumerable<ValueSet>, Action<IndexOperationEventArgs>)
Indexes the items in the Value
protected override void PerformIndexItems(IEnumerable<ValueSet> values, Action<IndexOperationEventArgs> onComplete)
Parameters
values
IEnumerable<ValueSet >onComplete
Action<IndexOperation >Event Args Called by the implementor once the items have been indexed
Remarks
Items will have been validated at this stage
RaiseIndexCommited(object, EventArgs)
Invokes the index commited event
Parameters
WaitForChanges()
Blocks the calling thread until the internal searcher can see latest documents
Remarks
Useful if you want a searcher to see the very latest changes. Typically this is not used and the searchers refresh on a near real time schedule.
WithThreadingMode(IndexThreadingMode)
Used to force the index into asynchronous or synchronous index processing
Parameters
mode
IndexThreading Mode
Returns
Events
DocumentWriting
Occurs when [document writing].
Event Type
IndexCommitted
Occors when the index is commited