Skip to content
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

Merges the changes from the release/3.0 branch to release/4.0 branch #345

Closed
wants to merge 10 commits into from
Closed
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
1 change: 0 additions & 1 deletion src/Examine.Core/Examine.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Nullable>enable</Nullable>
<LangVersion>9</LangVersion>
<NoWarn>RS0036</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Examine.Core/ExamineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public class ExamineManager : IDisposable, IExamineManager
/// <inheritdoc/>
public ExamineManager(IEnumerable<IIndex> indexes, IEnumerable<ISearcher> searchers)
{
foreach(IIndex i in indexes)
foreach(var i in indexes)
{
AddIndex(i);
}

foreach(ISearcher s in searchers)
foreach(var s in searchers)
{
AddSearcher(s);
}
Expand Down
56 changes: 30 additions & 26 deletions src/Examine.Core/OrderedDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public OrderedDictionary(IEqualityComparer<TKey> comparer) : base(comparer)
/// <inheritdoc/>
public TVal GetItem(int index)
{
if (index >= Count) throw new IndexOutOfRangeException();
if (index >= Count)
{
throw new IndexOutOfRangeException();
}

var found = base[index];

Expand All @@ -36,30 +39,31 @@ public TVal GetItem(int index)
/// <inheritdoc/>
public int IndexOf(TKey key)
{
if (base.Dictionary == null) return -1;
if (base.Dictionary.TryGetValue(key, out KeyValuePair<TKey, TVal> found))
if (Dictionary == null)
{
return -1;
}

if (Dictionary.TryGetValue(key, out var found))
{
return base.Items.IndexOf(found);
return Items.IndexOf(found);
}
return -1;
}

/// <inheritdoc/>
protected override TKey GetKeyForItem(KeyValuePair<TKey, TVal> item)
{
return item.Key;
}
protected override TKey GetKeyForItem(KeyValuePair<TKey, TVal> item) => item.Key;

/// <inheritdoc/>
public bool ContainsKey(TKey key)
{
return base.Contains(key);
}
public bool ContainsKey(TKey key) => Contains(key);

/// <inheritdoc/>
public void Add(TKey key, TVal value)
{
if (base.Contains(key)) throw new ArgumentException("The key " + key + " already exists in this collection");
if (Contains(key))
{
throw new ArgumentException("The key " + key + " already exists in this collection");
}

base.Add(new KeyValuePair<TKey, TVal>(key, value));
}
Expand All @@ -74,19 +78,19 @@ public bool TryGetValue(TKey key,
#endif
out TVal value)
{
if (base.Dictionary == null)
if (Dictionary == null)
{
value = default(TVal);
value = default;
return false;
}

if (base.Dictionary.TryGetValue(key, out KeyValuePair<TKey, TVal> found))
if (Dictionary.TryGetValue(key, out var found))
{
value = found.Value;
return true;
}

value = default(TVal);
value = default;
return false;
}

Expand All @@ -100,24 +104,24 @@ TVal IDictionary<TKey, TVal>.this[TKey key]
{
get
{
if (base.Dictionary != null &&
base.Dictionary.TryGetValue(key, out KeyValuePair<TKey, TVal> found))
if (Dictionary != null &&
Dictionary.TryGetValue(key, out var found))
{
return found.Value;
}
throw new KeyNotFoundException();
}
set
{
if (base.Dictionary != null &&
base.Dictionary.TryGetValue(key, out KeyValuePair<TKey, TVal> found))
if (Dictionary != null &&
Dictionary.TryGetValue(key, out var found))
{
var index = base.Items.IndexOf(found);
base.SetItem(index, new KeyValuePair<TKey, TVal>(key, value));
var index = Items.IndexOf(found);
SetItem(index, new KeyValuePair<TKey, TVal>(key, value));
}
else
{
base.Add(new KeyValuePair<TKey, TVal>(key, value));
Add(new KeyValuePair<TKey, TVal>(key, value));
}
}
}
Expand All @@ -126,9 +130,9 @@ TVal IDictionary<TKey, TVal>.this[TKey key]
private static readonly ICollection<TVal> EmptyValues = new List<TVal>();

/// <inheritdoc/>
public ICollection<TKey> Keys => base.Dictionary != null ? base.Dictionary.Keys : EmptyCollection;
public ICollection<TKey> Keys => Dictionary != null ? Dictionary.Keys : EmptyCollection;

/// <inheritdoc/>
public ICollection<TVal> Values => base.Dictionary != null ? base.Dictionary.Values.Select(x => x.Value).ToArray() : EmptyValues;
public ICollection<TVal> Values => Dictionary != null ? Dictionary.Values.Select(x => x.Value).ToArray() : EmptyValues;
}
}
36 changes: 23 additions & 13 deletions src/Examine.Core/Search/FacetLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ namespace Examine.Search
/// </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;
Components = components;
}

/// <summary>
Expand All @@ -26,20 +24,32 @@ public FacetLabel(string[] components)
/// <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);
Components = new string[1 + components.Length];
Components[0] = dimension;
Array.Copy(components, 0, Components, 1, components.Length);
}

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

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

// From Lucene.NET
public int CompareTo(IFacetLabel other)
/// <summary>
/// Compares one facet label to another.
/// </summary>
/// <remarks>
/// From Lucene.NET
/// </remarks>
/// <param name="other"></param>
/// <returns></returns>
public int CompareTo(IFacetLabel? other)
{
if (other == null)
{
return 1; // null sorts last
}

int len = Length < other.Length ? Length : other.Length;
for (int i = 0, j = 0; i < len; i++, j++)
{
Expand Down Expand Up @@ -67,11 +77,11 @@ public IFacetLabel Subpath(int length)
return new FacetLabel(Components);
}

List<string> subpathComponents = new List<string>(length);
var subpathComponents = new List<string>(length);
int index = 0;
while (index < length && index < _components.Length)
while (index < length && index < Components.Length)
{
subpathComponents.Add(_components[index]);
subpathComponents.Add(Components[index]);
index++;
}
return new FacetLabel(subpathComponents.ToArray());
Expand Down
18 changes: 3 additions & 15 deletions src/Examine.Core/Search/FacetResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,12 @@ public FacetResult(IEnumerable<IFacetValue> values)
}

/// <inheritdoc/>
public IEnumerator<IFacetValue> GetEnumerator()
{
return _values.GetEnumerator();
}
public IEnumerator<IFacetValue> GetEnumerator() => _values.GetEnumerator();

#if !NETSTANDARD2_0 && !NETSTANDARD2_1
[MemberNotNull(nameof(_dictValues))]
#endif
private void SetValuesDictionary()
{
if(_dictValues == null)
{
_dictValues = _values.ToDictionary(src => src.Label, src => src);
}
}
private void SetValuesDictionary() => _dictValues ??= _values.ToDictionary(src => src.Label, src => src);

/// <inheritdoc/>
public IFacetValue? Facet(string label)
Expand All @@ -54,9 +45,6 @@ public bool TryGetFacet(string label, out IFacetValue? facetValue)
}

/// <inheritdoc/>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
4 changes: 3 additions & 1 deletion src/Examine.Core/SearchResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

namespace Examine
{
/// <inheritdoc/>
/// <summary>
/// Represents a search result
/// </summary>
public class SearchResult : ISearchResult
{
private OrderedDictionary<string, string>? _fields;
Expand Down
8 changes: 6 additions & 2 deletions src/Examine.Host/AspNetCoreApplicationIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ namespace Examine
public class AspNetCoreApplicationIdentifier : IApplicationIdentifier
{
private readonly IServiceProvider _services;
private static readonly Lazy<string> _applicationId = new(() => Guid.NewGuid().ToString());

/// <inheritdoc/>
public AspNetCoreApplicationIdentifier(IServiceProvider services) => _services = services;
public AspNetCoreApplicationIdentifier(IServiceProvider services)
{
_services = services;
}


/// <inheritdoc/>
public string GetApplicationUniqueIdentifier() => _services.GetApplicationUniqueIdentifier();
public string GetApplicationUniqueIdentifier() => _services.GetApplicationUniqueIdentifier() ?? _applicationId.Value;
}
}
1 change: 0 additions & 1 deletion src/Examine.Host/Examine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Nullable>enable</Nullable>
<LangVersion>9</LangVersion>
<NoWarn>RS0036</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading
Loading