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
Extension Methods

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>

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

IsTaxonomyEnabled

Returns whether taxonomy indexing is enabled for this index

public bool IsTaxonomyEnabled { get; }

Property Value

bool

Remarks

Taxonomy indexing enables faceted search capabilities. When disabled, the taxonomy directory will not be created and faceted search features will not be available.

RunAsync

Indicates whether or this system will process the queue items asynchronously - 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, or null if taxonomy is not enabled

public virtual ILuceneTaxonomySearcher? TaxonomySearcher { get; }

Property Value

ILuceneTaxonomySearcher

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

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, or null if taxonomy is not enabled

public Directory? GetLuceneTaxonomyDirectory()

Returns

Directory

The taxonomy directory, or null if taxonomy is not enabled for this index

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

UpdateLuceneDocument(Term, Document)

Updates a Lucene document in the index.

protected virtual long? UpdateLuceneDocument(Term term, Document doc)

Parameters

term Term

The term used to identify the document to update.

doc Document

The document to be updated in the index.

Returns

long?

The generation number of the update operation, or null if the operation is not applicable.

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

Occurs when the index is committed

public event EventHandler? IndexCommitted

Event Type

EventHandler