Skip to content

Commit

Permalink
xdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
nzdev committed Jul 26, 2023
1 parent 3fae26d commit ef354c3
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 22 deletions.
19 changes: 15 additions & 4 deletions src/Examine.Core/Search/FacetLabel.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Examine.Search
{
/// <summary>
/// Holds a sequence of string components, specifying the hierarchical name of a category.
/// </summary>
public readonly struct FacetLabel : IFacetLabel
{
private readonly string[] _components;

/// <summary>
/// Constructor
/// </summary>
/// <param name="components">The components of this FacetLabel</param>
public FacetLabel(string[] components)
{
_components = components;
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="dimension">The name of the dimension that stores this FacetLabel</param>
/// <param name="components">>The components of this FacetLabel</param>
public FacetLabel(string dimension, string[] components)
{
_components = new string[1 + components.Length];
_components[0] = dimension;
Array.Copy(components, 0, _components, 1, components.Length);
}

/// <inheritdoc/>
public string[] Components => _components;

/// <inheritdoc/>
public int Length => _components.Length;

// From Lucene.NET
Expand Down
2 changes: 2 additions & 0 deletions src/Examine.Lucene/Directories/DirectoryFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ protected override Directory CreateDirectory(LuceneIndex luceneIndex, bool force
}
return dir;
}

/// <inheritdoc/>
protected override Directory CreateTaxonomyDirectory(LuceneIndex luceneIndex, bool forceUnlock)
{
Directory dir = _taxonomyDirectoryFactory(luceneIndex.Name + "taxonomy");
Expand Down
1 change: 1 addition & 0 deletions src/Examine.Lucene/Directories/DirectoryFactoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Directory IDirectoryFactory.CreateTaxonomyDirectory(LuceneIndex luceneIndex, boo
/// <inheritdoc/>
protected abstract Directory CreateDirectory(LuceneIndex luceneIndex, bool forceUnlock);

/// <inheritdoc/>
protected abstract Directory CreateTaxonomyDirectory(LuceneIndex luceneIndex, bool forceUnlock);

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected override Directory CreateDirectory(LuceneIndex luceneIndex, bool force
return dir;
}

/// <inheritdoc/>
protected override Directory CreateTaxonomyDirectory(LuceneIndex luceneIndex, bool forceUnlock)
{
var path = Path.Combine(_baseDir.FullName, luceneIndex.Name,"taxonomy");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public class SyncedTaxonomyFileSystemDirectoryFactory : FileSystemDirectoryFacto
{
private readonly DirectoryInfo _localDir;
private readonly ILoggerFactory _loggerFactory;
private ExamineTaxonomyReplicator _replicator;
private ExamineTaxonomyReplicator? _replicator;

/// <inheritdoc/>
public SyncedTaxonomyFileSystemDirectoryFactory(
DirectoryInfo localDir,
DirectoryInfo mainDir,
Expand All @@ -37,6 +38,7 @@ public SyncedTaxonomyFileSystemDirectoryFactory(
_loggerFactory = loggerFactory;
}

/// <inheritdoc/>
protected override Directory CreateDirectory(LuceneIndex luceneIndex, bool forceUnlock)
{
var luceneTaxonomyIndex = luceneIndex as LuceneIndex;
Expand Down Expand Up @@ -98,6 +100,7 @@ protected override Directory CreateDirectory(LuceneIndex luceneIndex, bool force
return localLuceneDir;
}

/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
Expand Down
15 changes: 15 additions & 0 deletions src/Examine.Lucene/ExamineTaxonomyReplicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public class ExamineTaxonomyReplicator : IDisposable
private bool _started = false;
private readonly ILogger<ExamineTaxonomyReplicator> _logger;

/// <summary>
/// Constructor
/// </summary>
/// <param name="loggerFactory"></param>
/// <param name="sourceIndex"></param>
/// <param name="destinationDirectory"></param>
/// <param name="destinationTaxonomyDirectory"></param>
/// <param name="tempStorage"></param>
public ExamineTaxonomyReplicator(
ILoggerFactory loggerFactory,
LuceneIndex sourceIndex,
Expand Down Expand Up @@ -99,6 +107,11 @@ public void ReplicateIndex()
_localReplicationClient.UpdateNow();
}

/// <summary>
/// Starts a thread that will replicate the index on a schedule
/// </summary>
/// <param name="milliseconds">Interval</param>
/// <exception cref="InvalidOperationException"></exception>
public void StartIndexReplicationOnSchedule(int milliseconds)
{
lock (_locker)
Expand Down Expand Up @@ -140,6 +153,7 @@ private void SourceIndex_IndexCommitted(object sender, EventArgs e)
_replicator.Publish(rev);
}

/// <inheritdoc/>
protected virtual void Dispose(bool disposing)
{
if (!_disposedValue)
Expand All @@ -154,6 +168,7 @@ protected virtual void Dispose(bool disposing)
}
}

/// <inheritdoc/>
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Expand Down
1 change: 1 addition & 0 deletions src/Examine.Lucene/Providers/BaseLuceneSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public override ISearchResults Search(string searchText, QueryOptions? options =
return sc.Execute(options);
}

/// <inheritdoc/>
public virtual void Dispose()
{

Expand Down
10 changes: 10 additions & 0 deletions src/Examine.Lucene/Providers/IIndexCommiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@

namespace Examine.Lucene.Providers
{
/// <summary>
/// This queues up a commit for the index so that a commit doesn't happen on every individual write since that is quite expensive
/// </summary>
public interface IIndexCommiter : IDisposable
{
/// <summary>
/// Commits the index to directory
/// </summary>
void CommitNow();

/// <summary>
/// Schedules the index to be commited to the directory
/// </summary>
void ScheduleCommit();
}
}
6 changes: 6 additions & 0 deletions src/Examine.Lucene/Providers/LuceneIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -949,18 +949,24 @@ private class IndexCommiter : DisposableObjectSlim, IIndexCommiter
/// </summary>
private const int MaxWaitMilliseconds = 300000;

/// <summary>
/// Constructor
/// </summary>
/// <param name="index">Index to commit</param>
public IndexCommiter(LuceneIndex index)
{
_index = index;
}

/// <inheritdoc/>
public void CommitNow()
{
_index._taxonomyWriter?.Commit();
_index._writer?.IndexWriter?.Commit();
_index.IndexCommitted?.Invoke(_index, EventArgs.Empty);
}

/// <inheritdoc/>
public void ScheduleCommit()
{
lock (_locker)
Expand Down
11 changes: 9 additions & 2 deletions src/Examine.Lucene/Providers/LuceneTaxonomySearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,29 @@ public class LuceneTaxonomySearcher : BaseLuceneSearcher, IDisposable, ILuceneTa
/// Constructor allowing for creating a NRT instance based on a given writer
/// </summary>
/// <param name="name"></param>
/// <param name="writer"></param>
/// <param name="searcherManager"></param>
/// <param name="analyzer"></param>
/// <param name="fieldValueTypeCollection"></param>
/// <param name="facetsConfig"></param>
public LuceneTaxonomySearcher(string name, SearcherTaxonomyManager searcherManager, Analyzer analyzer, FieldValueTypeCollection fieldValueTypeCollection, FacetsConfig facetsConfig)
: base(name, analyzer, facetsConfig)
{
_searcherManager = searcherManager;
_fieldValueTypeCollection = fieldValueTypeCollection;
}

/// <inheritdoc/>
public override ISearchContext GetSearchContext()
=> new TaxonomySearchContext(_searcherManager, _fieldValueTypeCollection);


/// <summary>
/// Gets the Taxonomy SearchContext
/// </summary>
/// <returns></returns>
public virtual ITaxonomySearchContext GetTaxonomySearchContext()
=> new TaxonomySearchContext(_searcherManager, _fieldValueTypeCollection);

/// <inheritdoc/>
protected virtual void Dispose(bool disposing)
{
if (!_disposedValue)
Expand All @@ -47,6 +53,7 @@ protected virtual void Dispose(bool disposing)
}
}

/// <inheritdoc/>
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Expand Down
7 changes: 7 additions & 0 deletions src/Examine.Lucene/Search/ITaxonomySearchContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
namespace Examine.Lucene.Search
{
/// <summary>
/// Search Context for Taxonomy Searcher
/// </summary>
public interface ITaxonomySearchContext : ISearchContext
{
/// <summary>
/// Gets the Search and Taxonomny Reader reference
/// </summary>
/// <returns></returns>
ITaxonomySearcherReference GetTaxonomyAndSearcher();
}
}
6 changes: 6 additions & 0 deletions src/Examine.Lucene/Search/ITaxonomySearcherReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

namespace Examine.Lucene.Search
{
/// <summary>
/// Represents a Taxonomy Searcher Reference
/// </summary>
public interface ITaxonomySearcherReference : ISearcherReference
{
/// <summary>
/// Taxonomy Reader for the sidecar taxonomy index
/// </summary>
DirectoryTaxonomyReader TaxonomyReader { get; }
}
}
17 changes: 12 additions & 5 deletions src/Examine.Lucene/Search/LuceneFacetLabel.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lucene.Net.Facet.Taxonomy;

namespace Examine.Lucene.Search
{
/// <summary>
/// Lucene Facet Label
/// </summary>
public class LuceneFacetLabel : Examine.Search.IFacetLabel
{
private readonly FacetLabel _facetLabel;

/// <summary>
/// Constructor
/// </summary>
/// <param name="facetLabel">Lucene Facet Label</param>
public LuceneFacetLabel(FacetLabel facetLabel)
{
_facetLabel = facetLabel;
}

/// <inheritdoc/>
public string[] Components => _facetLabel.Components;

/// <inheritdoc/>
public int Length => _facetLabel.Length;

/// <inheritdoc/>
public int CompareTo(Examine.Search.IFacetLabel other) => _facetLabel.CompareTo(new FacetLabel(other.Components));

/// <inheritdoc/>
public Examine.Search.IFacetLabel Subpath(int length) => new LuceneFacetLabel(_facetLabel.Subpath(length));
}
}
6 changes: 3 additions & 3 deletions src/Examine.Lucene/Search/LuceneQueryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class LuceneQueryOptions : QueryOptions
/// <param name="trackDocumentMaxScore">Whether to track the maximum document score. For best performance, if not needed, leave false.</param>
/// <param name="trackDocumentScores">Whether to Track Document Scores. For best performance, if not needed, leave false.</param>
/// <param name="facetSampling">Whether to apply Facet sampling to improve performance. If not required, leave null</param>
public LuceneQueryOptions(int skip, int? take = null, SearchAfterOptions searchAfter = null, bool trackDocumentScores = false, bool trackDocumentMaxScore = false, LuceneFacetSamplingQueryOptions facetSampling = null)
public LuceneQueryOptions(int skip, int? take = null, SearchAfterOptions? searchAfter = null, bool trackDocumentScores = false, bool trackDocumentMaxScore = false, LuceneFacetSamplingQueryOptions? facetSampling = null)
: base(skip, take)
{
TrackDocumentScores = trackDocumentScores;
Expand All @@ -39,14 +39,14 @@ public LuceneQueryOptions(int skip, int? take = null, SearchAfterOptions searchA
/// <summary>
/// Options for Searching After. Used for efficent deep paging.
/// </summary>
public SearchAfterOptions SearchAfter { get; }
public SearchAfterOptions? SearchAfter { get; }

/// <summary>
/// Options for Lucene Facet Sampling. If not set, no Facet Sampling is applied.
/// </summary>
/// <remarks>
/// Performance optimization for large sets
/// </remarks>
public LuceneFacetSamplingQueryOptions FacetRandomSampling { get; }
public LuceneFacetSamplingQueryOptions? FacetRandomSampling { get; }
}
}
12 changes: 9 additions & 3 deletions src/Examine.Lucene/Search/LuceneSearchResult.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Examine.Lucene.Search
{
/// <summary>
/// Lucene Index Search Result
/// </summary>
public class LuceneSearchResult : SearchResult, ISearchResult
{
/// <summary>
/// Constructor
/// </summary>
public LuceneSearchResult(string id, float score, Func<IDictionary<string, List<string>>> lazyFieldVals, int shardId)
: base(id, score, lazyFieldVals)
{
ShardIndex = shardId;
}

/// <summary>
/// Index Shard Id
/// </summary>
public int ShardIndex { get; }
}
}
7 changes: 7 additions & 0 deletions src/Examine.Lucene/Search/SearchAfterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ namespace Examine.Lucene.Search
public class SearchAfterOptions
{

/// <summary>
/// Constructor
/// </summary>
/// <param name="documentId">The Id of the last document in the previous result set. The search will search after this document</param>
/// <param name="documentScore"> The Score of the last document in the previous result set. The search will search after this document</param>
/// <param name="fields">Search fields. Should contain null or J2N.Int</param>
/// <param name="shardIndex">The index of the shard the doc belongs to</param>
public SearchAfterOptions(int documentId, float documentScore, object[] fields, int shardIndex)
{
DocumentId = documentId;
Expand Down
Loading

0 comments on commit ef354c3

Please sign in to comment.