Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
nzdev committed Mar 20, 2023
2 parents e0d5e6b + 226245e commit 5cf860c
Show file tree
Hide file tree
Showing 31 changed files with 1,708 additions and 736 deletions.
18 changes: 0 additions & 18 deletions src/Examine.Core/Search/FacetDoubleField.cs

This file was deleted.

18 changes: 0 additions & 18 deletions src/Examine.Core/Search/FacetFloatField.cs

This file was deleted.

23 changes: 0 additions & 23 deletions src/Examine.Core/Search/FacetFullTextField.cs

This file was deleted.

18 changes: 0 additions & 18 deletions src/Examine.Core/Search/FacetLongField.cs

This file was deleted.

16 changes: 0 additions & 16 deletions src/Examine.Core/Search/IFacetField.cs

This file was deleted.

43 changes: 43 additions & 0 deletions src/Examine.Core/Search/IFacetOperations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;

namespace Examine.Search
{

/// <summary>
/// Faceting operations
/// </summary>
public interface IFacetOperations : IQueryExecutor
{
/// <summary>
/// Add a facet string to the current query
/// </summary>
/// <param name="field"></param>
/// <param name="facetConfiguration"></param>
/// <returns></returns>
IFacetOperations Facet(string field, Action<IFacetQueryField> facetConfiguration = null);

/// <summary>
/// Add a facet string to the current query, filtered by a single value or multiple values
/// </summary>
/// <param name="field"></param>
/// <param name="facetConfiguration"></param>
/// <param name="values"></param>
/// <returns></returns>
IFacetOperations Facet(string field, Action<IFacetQueryField> facetConfiguration = null, params string[] values);

/// <summary>
/// Add a range facet to the current query
/// </summary>
IFacetOperations Facet(string field, params DoubleRange[] doubleRanges);

/// <summary>
/// Add a range facet to the current query
/// </summary>
IFacetOperations Facet(string field, params FloatRange[] floatRanges);

/// <summary>
/// Add a range facet to the current query
/// </summary>
IFacetOperations Facet(string field, params Int64Range[] longRanges);
}
}
35 changes: 5 additions & 30 deletions src/Examine.Core/Search/IFaceting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,15 @@
namespace Examine.Search
{
/// <summary>
/// Faceting operations
/// Allows for selecting facets to return in your query
/// </summary>
public interface IFaceting : IQueryExecutor
public interface IFaceting
{
/// <summary>
/// Add a facet string to the current query
/// Allows for selecting facets to return in your query
/// </summary>
/// <param name="field"></param>
/// <param name="facetConfiguration"></param>
/// <param name="facets"></param>
/// <returns></returns>
IFaceting Facet(string field, Action<IFacetQueryField> facetConfiguration = null);

/// <summary>
/// Add a facet string to the current query, filtered by a single value or multiple values
/// </summary>
/// <param name="field"></param>
/// <param name="facetConfiguration"></param>
/// <param name="values"></param>
/// <returns></returns>
IFaceting Facet(string field, Action<IFacetQueryField> facetConfiguration = null, params string[] values);

/// <summary>
/// Add a range facet to the current query
/// </summary>
IFaceting Facet(string field, params DoubleRange[] doubleRanges);

/// <summary>
/// Add a range facet to the current query
/// </summary>
IFaceting Facet(string field, params FloatRange[] floatRanges);

/// <summary>
/// Add a range facet to the current query
/// </summary>
IFaceting Facet(string field, params Int64Range[] longRanges);
IQueryExecutor WithFacets(Action<IFacetOperations> facets);
}
}
9 changes: 1 addition & 8 deletions src/Examine.Core/Search/IOrdering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ public interface IOrdering : IQueryExecutor
/// Return all fields in the index
/// </summary>
/// <returns></returns>
IOrdering SelectAllFields();

/// <summary>
/// Allows for selecting facets to return in your query
/// </summary>
/// <param name="facets"></param>
/// <returns></returns>
IQueryExecutor WithFacets(Action<IFaceting> facets);
IOrdering SelectAllFields();
}
}
22 changes: 22 additions & 0 deletions src/Examine.Core/Search/OrderingExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace Examine.Search
{
public static class OrderingExtensions
{
/// <summary>
/// Allows for selecting facets to return in your query
/// </summary>
/// <param name="facets"></param>
/// <returns></returns>
public static IQueryExecutor WithFacets(this IOrdering ordering, Action<IFacetOperations> facets)
{
if (ordering is IFaceting faceting)
{
return faceting.WithFacets(facets);
}

throw new NotSupportedException("The current implementation of Examine does not support faceting");
}
}
}
20 changes: 18 additions & 2 deletions src/Examine.Lucene/Indexing/DateTimeType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using Examine.Lucene.Providers;
using Examine.Lucene.Search;
using Examine.Search;
using Lucene.Net.Documents;
using Lucene.Net.Facet;
using Lucene.Net.Facet.SortedSet;
Expand All @@ -9,7 +12,7 @@
namespace Examine.Lucene.Indexing
{

public class DateTimeType : IndexFieldRangeValueType<DateTime>
public class DateTimeType : IndexFieldRangeValueType<DateTime>, IIndexFacetValueType
{
public DateResolution Resolution { get; }

Expand All @@ -21,14 +24,24 @@ public class DateTimeType : IndexFieldRangeValueType<DateTime>
/// </summary>
public override string SortableFieldName => FieldName;

public DateTimeType(string fieldName, ILoggerFactory logger, DateResolution resolution, bool store = true, bool isFacetable = false, bool taxonomyIndex = false)
/// <inheritdoc/>
public bool IsTaxonomyFaceted => _taxonomyIndex;

public DateTimeType(string fieldName, ILoggerFactory logger, DateResolution resolution, bool store, bool isFacetable, bool taxonomyIndex)
: base(fieldName, logger, store)
{
Resolution = resolution;
_isFacetable = isFacetable;
_taxonomyIndex = taxonomyIndex;
}

public DateTimeType(string fieldName, ILoggerFactory logger, DateResolution resolution, bool store = true)
: base(fieldName, logger, store)
{
Resolution = resolution;
_isFacetable = false;
}

public override void AddValue(Document doc, object value)
{
// Support setting taxonomy path
Expand Down Expand Up @@ -95,5 +108,8 @@ public override Query GetQuery(DateTime? lower, DateTime? upper, bool lowerInclu
lower != null ? DateToLong(lower.Value) : (long?)null,
upper != null ? DateToLong(upper.Value) : (long?)null, lowerInclusive, upperInclusive);
}

public virtual IEnumerable<KeyValuePair<string, IFacetResult>> ExtractFacets(IFacetExtractionContext facetExtractionContext, IFacetField field)
=> field.ExtractFacets(facetExtractionContext);
}
}
18 changes: 16 additions & 2 deletions src/Examine.Lucene/Indexing/DoubleType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Collections.Generic;
using Examine.Lucene.Providers;
using Examine.Lucene.Search;
using Examine.Search;
using Lucene.Net.Documents;
using Lucene.Net.Facet;
using Lucene.Net.Facet.SortedSet;
Expand All @@ -7,23 +10,32 @@

namespace Examine.Lucene.Indexing
{
public class DoubleType : IndexFieldRangeValueType<double>
public class DoubleType : IndexFieldRangeValueType<double>, IIndexFacetValueType
{
private readonly bool _isFacetable;
private readonly bool _taxonomyIndex;

public DoubleType(string fieldName, ILoggerFactory logger, bool store = true, bool isFacetable = false, bool taxonomyIndex = false)
public DoubleType(string fieldName, ILoggerFactory logger, bool store, bool isFacetable, bool taxonomyIndex = false)
: base(fieldName, logger, store)
{
_isFacetable = isFacetable;
_taxonomyIndex = taxonomyIndex;
}

public DoubleType(string fieldName, ILoggerFactory logger, bool store = true)
: base(fieldName, logger, store)
{
_isFacetable = false;
}

/// <summary>
/// Can be sorted by the normal field name
/// </summary>
public override string SortableFieldName => FieldName;

/// <inheritdoc/>
public bool IsTaxonomyFaceted => _taxonomyIndex;

public override void AddValue(Document doc, object value)
{
// Support setting taxonomy path
Expand Down Expand Up @@ -73,5 +85,7 @@ public override Query GetQuery(double? lower, double? upper, bool lowerInclusive
lower ?? double.MinValue,
upper ?? double.MaxValue, lowerInclusive, upperInclusive);
}
public virtual IEnumerable<KeyValuePair<string, IFacetResult>> ExtractFacets(IFacetExtractionContext facetExtractionContext, IFacetField field)
=> field.ExtractFacets(facetExtractionContext);
}
}
27 changes: 25 additions & 2 deletions src/Examine.Lucene/Indexing/FullTextType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.IO;
using Examine.Lucene.Analyzers;
using Examine.Lucene.Providers;
using Examine.Lucene.Search;
using Examine.Search;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Miscellaneous;
using Lucene.Net.Analysis.TokenAttributes;
Expand All @@ -23,7 +25,7 @@ namespace Examine.Lucene.Indexing
/// do an exact match search if the term is less than 4 chars, else it will do a full text search on the phrase
/// with a higher boost, then
/// </remarks>
public class FullTextType : IndexFieldValueTypeBase
public class FullTextType : IndexFieldValueTypeBase, IIndexFacetValueType
{
private readonly bool _sortable;
private readonly Analyzer _analyzer;
Expand All @@ -38,7 +40,7 @@ public class FullTextType : IndexFieldValueTypeBase
/// Defaults to <see cref="CultureInvariantStandardAnalyzer"/>
/// </param>
/// <param name="sortable"></param>
public FullTextType(string fieldName, ILoggerFactory logger, Analyzer analyzer = null, bool sortable = false, bool isFacetable = false, bool taxonomyIndex = false)
public FullTextType(string fieldName, ILoggerFactory logger, bool sortable = false, bool isFacetable = false, Analyzer analyzer = null, bool taxonomyIndex = false)
: base(fieldName, logger, true)
{
_sortable = sortable;
Expand All @@ -47,13 +49,32 @@ public FullTextType(string fieldName, ILoggerFactory logger, Analyzer analyzer =
_taxonomyIndex = taxonomyIndex;
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="fieldName"></param>
/// <param name="analyzer">
/// Defaults to <see cref="CultureInvariantStandardAnalyzer"/>
/// </param>
/// <param name="sortable"></param>
public FullTextType(string fieldName, ILoggerFactory logger, Analyzer analyzer = null, bool sortable = false)
: base(fieldName, logger, true)
{
_sortable = sortable;
_analyzer = analyzer ?? new CultureInvariantStandardAnalyzer();
_isFacetable = false;
}

/// <summary>
/// Can be sorted by a concatenated field name since to be sortable it cannot be analyzed
/// </summary>
public override string SortableFieldName => _sortable ? ExamineFieldNames.SortedFieldNamePrefix + FieldName : null;

public override Analyzer Analyzer => _analyzer;

/// <inheritdoc/>
public bool IsTaxonomyFaceted => _taxonomyIndex;

public override void AddValue(Document doc, object value)
{
// Support setting taxonomy path
Expand Down Expand Up @@ -185,5 +206,7 @@ public override Query GetQuery(string query)
return GenerateQuery(FieldName, query, _analyzer);
}

public virtual IEnumerable<KeyValuePair<string, IFacetResult>> ExtractFacets(IFacetExtractionContext facetExtractionContext, IFacetField field)
=> field.ExtractFacets(facetExtractionContext);
}
}
Loading

0 comments on commit 5cf860c

Please sign in to comment.