Skip to content

Commit

Permalink
feat: Nullable enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
nikcio committed Dec 6, 2022
1 parent a0faff0 commit f4fc5be
Show file tree
Hide file tree
Showing 58 changed files with 304 additions and 221 deletions.
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 @@ -39,7 +39,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 @@ -113,13 +113,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 @@ -22,10 +22,10 @@ protected BaseSearchProvider(string name)
/// <param name="searchText"></param>
/// <param name="maxResults"></param>
/// <returns></returns>
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 @@ -5,6 +5,8 @@
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Description>Examine is an abstraction for indexing and search operations with implementations such as Lucene.Net</Description>
<PackageTags>examine search index</PackageTags>
<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 @@ -29,7 +29,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 All @@ -27,11 +28,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 @@ -32,7 +32,7 @@ public FieldDefinition(string name, string type)

public bool Equals(FieldDefinition other) => string.Equals(Name, other.Name) && string.Equals(Type, other.Type);

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 @@ -29,7 +30,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 <see cref="AddSearcher"/> or via config
Expand All @@ -39,7 +44,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);

}
}
6 changes: 3 additions & 3 deletions src/Examine.Core/ISearchResult.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;

namespace Examine
{
Expand Down Expand Up @@ -41,6 +41,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 @@ -15,7 +15,7 @@ public interface ISearcher
/// <param name="searchText">The search text or a native query</param>
/// <param name="maxResults"></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 @@ -25,6 +25,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 @@ -5,6 +5,6 @@ public class IndexOptions
public IndexOptions() => FieldDefinitions = new FieldDefinitionCollection();

public FieldDefinitionCollection FieldDefinitions { get; set; }
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 @@ -8,17 +8,17 @@ namespace Examine
public class IndexingErrorEventArgs : EventArgs
{

public IndexingErrorEventArgs(IIndex index, string message, string itemId, Exception exception)
public IndexingErrorEventArgs(IIndex index, string message, string? itemId, Exception? exception)
{
Index = index;
ItemId = itemId;
Message = message;
Exception = exception;
}

public Exception Exception { get; }
public Exception? Exception { get; }
public string Message { get; }
public IIndex Index { get; }
public string ItemId { get; }
public string? ItemId { get; }
}
}
18 changes: 13 additions & 5 deletions src/Examine.Core/OrderedDictionary.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
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
{
public OrderedDictionary()
{
Expand Down Expand Up @@ -56,7 +57,14 @@ public void Add(TKey key, TVal value)
base.Add(new KeyValuePair<TKey, TVal>(key, value));
}

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 @@ -89,7 +97,7 @@ TVal IDictionary<TKey, TVal>.this[TKey key]
{
return found.Value;
}
return default(TVal);
return default(TVal); // TODO: should this throw instead
}
set
{
Expand All @@ -113,4 +121,4 @@ TVal IDictionary<TKey, TVal>.this[TKey key]

public ICollection<TVal> Values => base.Dictionary != null ? base.Dictionary.Values.Select(x => x.Value).ToArray() : EmptyValues;
}
}
}
2 changes: 1 addition & 1 deletion src/Examine.Core/Search/FacetResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public IEnumerator<IFacetValue> GetEnumerator()
return _values.GetEnumerator();
}

public IFacetValue Facet(string label)
public IFacetValue? Facet(string label)
{
return _values.FirstOrDefault(field => field.Label.Equals(label));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Examine.Core/Search/IFacetResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public interface IFacetResult : IEnumerable<IFacetValue>
/// </summary>
/// <param name="label"></param>
/// <returns></returns>
IFacetValue Facet(string label);
IFacetValue? Facet(string label);
}
}
6 changes: 3 additions & 3 deletions src/Examine.Core/Search/INestedQuery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;

namespace Examine.Search
{
Expand Down Expand Up @@ -85,7 +85,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 All @@ -100,4 +100,4 @@ public interface INestedQuery
/// <returns></returns>
INestedBooleanOperation RangeQuery<T>(string[] fields, T? min, T? max, bool minInclusive = true, bool maxInclusive = true) where T : struct;
}
}
}
2 changes: 1 addition & 1 deletion src/Examine.Core/Search/IQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,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);
}
}
8 changes: 4 additions & 4 deletions src/Examine.Core/SearchResult.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
Expand All @@ -7,7 +7,7 @@ namespace Examine
{
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 @@ -94,14 +94,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

0 comments on commit f4fc5be

Please sign in to comment.