Skip to content

Facets nullable (#311 & #307) #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@
<PropertyGroup Condition="'$(MSBuildProjectName)' != 'Examine.Web.Demo' AND '$(MSBuildProjectName)' != 'Examine.Test'">
<TargetFrameworks>net6.0;netstandard2.1;netstandard2.0</TargetFrameworks>
</PropertyGroup>


<!-- Disable the nullable warnings when compiling for .NET Standard 2.0 -->
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<NoWarn>$(NoWarn);nullable</NoWarn>
</PropertyGroup>
</Project>
8 changes: 4 additions & 4 deletions src/Examine.Core/BaseIndexProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected BaseIndexProvider(ILoggerFactory loggerFactory, string name,
/// <summary>
/// A validator to validate a value set before it's indexed
/// </summary>
public IValueSetValidator ValueSetValidator => _indexOptions.Validator;
public IValueSetValidator? ValueSetValidator => _indexOptions.Validator;

/// <summary>
/// Ensures that the node being indexed is of a correct type
Expand Down Expand Up @@ -110,13 +110,13 @@ public void DeleteFromIndex(IEnumerable<string> itemIds)
#region Events

/// <inheritdoc />
public event EventHandler<IndexOperationEventArgs> IndexOperationComplete;
public event EventHandler<IndexOperationEventArgs>? IndexOperationComplete;

/// <inheritdoc />
public event EventHandler<IndexingErrorEventArgs> IndexingError;
public event EventHandler<IndexingErrorEventArgs>? IndexingError;

/// <inheritdoc />
public event EventHandler<IndexingItemEventArgs> TransformingIndexValues;
public event EventHandler<IndexingItemEventArgs>? TransformingIndexValues;

#endregion

Expand Down
4 changes: 2 additions & 2 deletions src/Examine.Core/BaseSearchProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ protected BaseSearchProvider(string name)
public string Name { get; }

/// <inheritdoc/>
public abstract ISearchResults Search(string searchText, QueryOptions options = null);
public abstract ISearchResults Search(string searchText, QueryOptions? options = null);

/// <inheritdoc />
public abstract IQuery CreateQuery(string category = null, BooleanOperation defaultOperation = BooleanOperation.And);
public abstract IQuery CreateQuery(string? category = null, BooleanOperation defaultOperation = BooleanOperation.And);

}
}
2 changes: 2 additions & 0 deletions src/Examine.Core/Examine.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<Description>Examine is an abstraction for indexing and search operations with implementations such as Lucene.Net</Description>
<PackageTags>examine search index</PackageTags>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Nullable>enable</Nullable>
<LangVersion>9</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Examine.Core/ExamineExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static T GetNamedOptions<T>(this IOptionsMonitor<T> optionsMonitor, strin
/// <returns></returns>
public static IIndex GetIndex(this IExamineManager examineManager, string indexName)
{
if (examineManager.TryGetIndex(indexName, out IIndex index))
if (examineManager.TryGetIndex(indexName, out IIndex? index))
{
return index;
}
Expand Down
13 changes: 11 additions & 2 deletions src/Examine.Core/ExamineManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace Examine
Expand Down Expand Up @@ -28,11 +29,19 @@ public ExamineManager(IEnumerable<IIndex> indexes, IEnumerable<ISearcher> search
private readonly ConcurrentDictionary<string, ISearcher> _searchers = new ConcurrentDictionary<string, ISearcher>(StringComparer.InvariantCultureIgnoreCase);

/// <inheritdoc />
public bool TryGetSearcher(string searcherName, out ISearcher searcher) =>
public bool TryGetSearcher(string searcherName,
#if !NETSTANDARD2_0
[MaybeNullWhen(false)]
#endif
out ISearcher searcher) =>
(searcher = _searchers.TryGetValue(searcherName, out var s) ? s : null) != null;

/// <inheritdoc />
public bool TryGetIndex(string indexName, out IIndex index) =>
public bool TryGetIndex(string indexName,
#if !NETSTANDARD2_0
[MaybeNullWhen(false)]
#endif
out IIndex index) =>
(index = _indexers.TryGetValue(indexName, out var i) ? i : null) != null;

/// <inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion src/Examine.Core/FieldDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public FieldDefinition(string name, string type)
public bool Equals(FieldDefinition other) => string.Equals(Name, other.Name) && string.Equals(Type, other.Type);

/// <inheritdoc/>
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
return obj is FieldDefinition definition && Equals(definition);
Expand Down
13 changes: 11 additions & 2 deletions src/Examine.Core/IExamineManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace Examine
Expand Down Expand Up @@ -35,7 +36,11 @@ public interface IExamineManager
/// <param name="indexName"></param>
/// <param name="index"></param>
/// <returns>true if the index was found by name</returns>
bool TryGetIndex(string indexName, out IIndex index);
bool TryGetIndex(string indexName,
#if !NETSTANDARD2_0
[MaybeNullWhen(false)]
#endif
out IIndex index);

/// <summary>
/// Returns a searcher that was registered with AddExamineSearcher or via config
Expand All @@ -45,7 +50,11 @@ public interface IExamineManager
/// <returns>
/// true if the searcher was found by name
/// </returns>
bool TryGetSearcher(string searcherName, out ISearcher searcher);
bool TryGetSearcher(string searcherName,
#if !NETSTANDARD2_0
[MaybeNullWhen(false)]
#endif
out ISearcher searcher);

}
}
2 changes: 1 addition & 1 deletion src/Examine.Core/ISearchResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public interface ISearchResult
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
string this[string key] { get; }
string? this[string key] { get; }
}
}
4 changes: 2 additions & 2 deletions src/Examine.Core/ISearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface ISearcher
/// <param name="searchText">The search text or a native query</param>
/// <param name="options"></param>
/// <returns>Search Results</returns>
ISearchResults Search(string searchText, QueryOptions options = null);
ISearchResults Search(string searchText, QueryOptions? options = null);

/// <summary>
/// Creates a search criteria instance as required by the implementation
Expand All @@ -28,6 +28,6 @@ public interface ISearcher
/// <returns>
/// An instance of <see cref="IQueryExecutor"/>
/// </returns>
IQuery CreateQuery(string category = null, BooleanOperation defaultOperation = BooleanOperation.And);
IQuery CreateQuery(string? category = null, BooleanOperation defaultOperation = BooleanOperation.And);
}
}
2 changes: 1 addition & 1 deletion src/Examine.Core/IndexOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public class IndexOptions
/// <summary>
/// The validator for the <see cref="IIndex"/>
/// </summary>
public IValueSetValidator Validator { get; set; }
public IValueSetValidator? Validator { get; set; }
}
}
6 changes: 3 additions & 3 deletions src/Examine.Core/IndexingErrorEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Examine
public class IndexingErrorEventArgs : EventArgs
{
/// <inheritdoc/>
public IndexingErrorEventArgs(IIndex index, string message, string itemId, Exception exception)
public IndexingErrorEventArgs(IIndex index, string message, string? itemId, Exception? exception)
{
Index = index;
ItemId = itemId;
Expand All @@ -22,7 +22,7 @@ public IndexingErrorEventArgs(IIndex index, string message, string itemId, Excep
/// <summary>
/// The exception of the error
/// </summary>
public Exception Exception { get; }
public Exception? Exception { get; }

/// <summary>
/// The message of the error
Expand All @@ -37,6 +37,6 @@ public IndexingErrorEventArgs(IIndex index, string message, string itemId, Excep
/// <summary>
/// The item id
/// </summary>
public string ItemId { get; }
public string? ItemId { get; }
}
}
14 changes: 11 additions & 3 deletions src/Examine.Core/OrderedDictionary.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace Examine
Expand All @@ -10,7 +11,7 @@ namespace Examine
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TVal"></typeparam>
public class OrderedDictionary<TKey, TVal> : KeyedCollection<TKey, KeyValuePair<TKey, TVal>>, IDictionary<TKey, TVal>, IReadOnlyDictionary<TKey, TVal>
public class OrderedDictionary<TKey, TVal> : KeyedCollection<TKey, KeyValuePair<TKey, TVal>>, IDictionary<TKey, TVal>, IReadOnlyDictionary<TKey, TVal> where TKey : notnull
{
/// <inheritdoc/>
public OrderedDictionary()
Expand Down Expand Up @@ -64,7 +65,14 @@ public void Add(TKey key, TVal value)
}

/// <inheritdoc/>
public bool TryGetValue(TKey key, out TVal value)
#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes).
// Justification for warning disabled: IDictionary is missing [MaybeNullWhen(false)] in Netstandard 2.1
public bool TryGetValue(TKey key,
#pragma warning restore CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes).
#if !NETSTANDARD2_0
[MaybeNullWhen(false)]
#endif
out TVal value)
{
if (base.Dictionary == null)
{
Expand Down Expand Up @@ -97,7 +105,7 @@ TVal IDictionary<TKey, TVal>.this[TKey key]
{
return found.Value;
}
return default(TVal);
throw new KeyNotFoundException();
}
set
{
Expand Down
13 changes: 11 additions & 2 deletions src/Examine.Core/Search/FacetResult.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace Examine.Search
Expand All @@ -8,7 +9,12 @@ namespace Examine.Search
public class FacetResult : IFacetResult
{
private readonly IEnumerable<IFacetValue> _values;
#if NETSTANDARD2_1
[AllowNull]
private IDictionary<string, IFacetValue> _dictValues;
#else
private IDictionary<string, IFacetValue>? _dictValues;
#endif

/// <inheritdoc/>
public FacetResult(IEnumerable<IFacetValue> values)
Expand All @@ -22,6 +28,9 @@ public IEnumerator<IFacetValue> GetEnumerator()
return _values.GetEnumerator();
}

#if !NETSTANDARD2_0 && !NETSTANDARD2_1
[MemberNotNull(nameof(_dictValues))]
#endif
private void SetValuesDictionary()
{
if(_dictValues == null)
Expand All @@ -31,14 +40,14 @@ private void SetValuesDictionary()
}

/// <inheritdoc/>
public IFacetValue Facet(string label)
public IFacetValue? Facet(string label)
{
SetValuesDictionary();
return _dictValues[label];
}

/// <inheritdoc/>
public bool TryGetFacet(string label, out IFacetValue facetValue)
public bool TryGetFacet(string label, out IFacetValue? facetValue)
{
SetValuesDictionary();
return _dictValues.TryGetValue(label, out facetValue);
Expand Down
4 changes: 2 additions & 2 deletions src/Examine.Core/Search/IFacetOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface IFacetOperations : IQueryExecutor
/// <param name="field"></param>
/// <param name="facetConfiguration"></param>
/// <returns></returns>
IFacetOperations Facet(string field, Action<IFacetQueryField> facetConfiguration = null);
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
Expand All @@ -23,7 +23,7 @@ public interface IFacetOperations : IQueryExecutor
/// <param name="facetConfiguration"></param>
/// <param name="values"></param>
/// <returns></returns>
IFacetOperations Facet(string field, Action<IFacetQueryField> facetConfiguration = null, params string[] values);
IFacetOperations Facet(string field, Action<IFacetQueryField>? facetConfiguration = null, params string[] values);

/// <summary>
/// Add a range facet to the current query
Expand Down
4 changes: 2 additions & 2 deletions src/Examine.Core/Search/IFacetResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public interface IFacetResult : IEnumerable<IFacetValue>
/// </summary>
/// <param name="label"></param>
/// <returns></returns>
IFacetValue Facet(string label);
IFacetValue? Facet(string label);

/// <summary>
/// Trys to get a facet value for a label
/// </summary>
/// <param name="label"></param>
/// <param name="facetValue"></param>
/// <returns></returns>
bool TryGetFacet(string label, out IFacetValue facetValue);
bool TryGetFacet(string label, out IFacetValue? facetValue);
}
}
2 changes: 1 addition & 1 deletion src/Examine.Core/Search/INestedQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public interface INestedQuery
/// <param name="query"></param>
/// <param name="fields"></param>
/// <returns></returns>
INestedBooleanOperation ManagedQuery(string query, string[] fields = null);
INestedBooleanOperation ManagedQuery(string query, string[]? fields = null);

/// <summary>
/// Matches items as defined by the IIndexFieldValueType used for the fields specified.
Expand Down
2 changes: 1 addition & 1 deletion src/Examine.Core/Search/IQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public interface IQuery
/// <param name="query"></param>
/// <param name="fields"></param>
/// <returns></returns>
IBooleanOperation ManagedQuery(string query, string[] fields = null);
IBooleanOperation ManagedQuery(string query, string[]? fields = null);

/// <summary>
/// Matches items as defined by the IIndexFieldValueType used for the fields specified.
Expand Down
2 changes: 1 addition & 1 deletion src/Examine.Core/Search/IQueryExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public interface IQueryExecutor
/// <summary>
/// Executes the query
/// </summary>
ISearchResults Execute(QueryOptions options = null);
ISearchResults Execute(QueryOptions? options = null);
}
}
6 changes: 3 additions & 3 deletions src/Examine.Core/SearchResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Examine
/// <inheritdoc/>
public class SearchResult : ISearchResult
{
private OrderedDictionary<string, string> _fields;
private OrderedDictionary<string, string>? _fields;
private readonly Lazy<OrderedDictionary<string, IReadOnlyList<string>>> _fieldValues;

/// <summary>
Expand Down Expand Up @@ -98,14 +98,14 @@ public IEnumerable<string> GetValues(string key)
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public string this[string key] => Values.TryGetValue(key, out var single) ? single : null;
public string? this[string key] => Values.TryGetValue(key, out var single) ? single : null;

/// <summary>
/// Override this method so that the Distinct() operator works
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (obj == null || GetType() != obj.GetType())
return false;
Expand Down
Loading