Table of Contents

Class LuceneIndex

Namespace
Examine.Lucene.Providers
Assembly
Examine.Lucene.dll

Abstract object containing all of the logic used to use Lucene as an indexer

public class LuceneIndex : BaseIndexProvider, IIndex, IDisposable, IIndexStats, ReferenceManager.IRefreshListener
Inheritance
LuceneIndex
Implements
ReferenceManager.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 string
indexOptions IOptionsMonitor<LuceneDirectoryIndexOptions>

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 string
indexOptions IOptionsMonitor<LuceneDirectoryIndexOptions>
indexCommiterFactory Func<LuceneIndex, IIndexCommiter>
writer IndexWriter

Exceptions

ArgumentNullException
InvalidOperationException

Properties

DefaultAnalyzer

The default analyzer to use when indexing content, by default, this is set to StandardAnalyzer

public Analyzer DefaultAnalyzer { get; }

Property Value

Analyzer

FieldAnalyzer

Gets the field ananlyzer

public PerFieldAnalyzerWrapper FieldAnalyzer { get; }

Property Value

PerFieldAnalyzerWrapper

FieldValueTypeCollection

Returns the FieldValueTypeCollection configured for this index

public FieldValueTypeCollection FieldValueTypeCollection { get; }

Property Value

FieldValueTypeCollection

IndexWriter

Gets the TrackingIndexWriter for the current directory

public TrackingIndexWriter IndexWriter { get; }

Property Value

TrackingIndexWriter

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

public bool RunAsync { get; protected set; }

Property Value

bool

Searcher

Gets a searcher for the index

public override ISearcher Searcher { get; }

Property Value

ISearcher

TaxonomySearcher

Gets a Taxonomy searcher for the index

public virtual ILuceneTaxonomySearcher? TaxonomySearcher { get; }

Property Value

ILuceneTaxonomySearcher

TaxonomyWriter

Gets the taxonomy writer for the current index

public DirectoryTaxonomyWriter TaxonomyWriter { get; }

Property Value

DirectoryTaxonomyWriter

Methods

AddDocument(Document, ValueSet)

Collects the data for the fields and adds the document which is then committed into Lucene.Net's index

protected virtual void AddDocument(Document doc, ValueSet valueSet)

Parameters

doc Document
valueSet ValueSet

The data to index.

CreateFieldValueTypes(IReadOnlyDictionary<string, IFieldValueTypeFactory>?)

Creates the FieldValueTypeCollection for this index

protected virtual FieldValueTypeCollection CreateFieldValueTypes(IReadOnlyDictionary<string, IFieldValueTypeFactory>? indexValueTypesFactory = null)

Parameters

indexValueTypesFactory IReadOnlyDictionary<string, IFieldValueTypeFactory>

Returns

FieldValueTypeCollection

CreateIndex()

Creates a new index, any existing index will be deleted

public override void CreateIndex()

CreateIndexWriter(Directory?)

Method that creates the IndexWriter

protected virtual IndexWriter CreateIndexWriter(Directory? d)

Parameters

d Directory

Returns

IndexWriter

CreateTaxonomyWriter(Directory?)

Method that creates the IndexWriter

protected virtual DirectoryTaxonomyWriter CreateTaxonomyWriter(Directory? d)

Parameters

d Directory

Returns

DirectoryTaxonomyWriter

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

EnsureIndex(bool)

Creates a brand new index, this will override any existing index with an empty one

public void EnsureIndex(bool forceOverwrite)

Parameters

forceOverwrite bool

GetDocumentCount()

Gets the ammount of documents in the index

public long GetDocumentCount()

Returns

long

GetFieldNames()

Gets the field names in the index

public IEnumerable<string> GetFieldNames()

Returns

IEnumerable<string>

GetLuceneDirectory()

Returns the Lucene Directory used to store the index

public Directory? GetLuceneDirectory()

Returns

Directory

GetLuceneTaxonomyDirectory()

Returns the Lucene Directory used to store the taxonomy index

public Directory? GetLuceneTaxonomyDirectory()

Returns

Directory

IndexExists()

Check if there is an index in the index folder

public override bool IndexExists()

Returns

bool

IndexReady()

Checks if the index is ready to open/write to.

protected bool IndexReady()

Returns

bool

IsReadable(out Exception?)

Check if the index is readable/healthy

public bool IsReadable(out Exception? ex)

Parameters

ex Exception

Returns

bool

OnDocumentWriting(DocumentWritingEventArgs)

Called when a document in writing

protected virtual void OnDocumentWriting(DocumentWritingEventArgs docArgs)

Parameters

docArgs DocumentWritingEventArgs

OnIndexingError(IndexingErrorEventArgs)

Called when an indexing error occurs

protected override void OnIndexingError(IndexingErrorEventArgs e)

Parameters

e IndexingErrorEventArgs

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<IndexOperationEventArgs>

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 ValueSet

protected override void PerformIndexItems(IEnumerable<ValueSet> values, Action<IndexOperationEventArgs> onComplete)

Parameters

values IEnumerable<ValueSet>
onComplete Action<IndexOperationEventArgs>

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

protected void RaiseIndexCommited(object sender, EventArgs e)

Parameters

sender object
e EventArgs

WaitForChanges()

Blocks the calling thread until the internal searcher can see latest documents

public void WaitForChanges()

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

public IDisposable WithThreadingMode(IndexThreadingMode mode)

Parameters

mode IndexThreadingMode

Returns

IDisposable

Events

DocumentWriting

Occurs when [document writing].

public event EventHandler<DocumentWritingEventArgs>? DocumentWriting

Event Type

EventHandler<DocumentWritingEventArgs>

IndexCommitted

Occors when the index is commited

public event EventHandler? IndexCommitted

Event Type

EventHandler