-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e78a6d5
commit 40d1100
Showing
6 changed files
with
28 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 8 additions & 73 deletions
81
src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Models/ElasticsearchResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,28 @@ | ||
using System.Text.Json.Nodes; | ||
|
||
namespace OrchardCore.Search.Elasticsearch; | ||
|
||
public class ElasticsearchResult | ||
{ | ||
public List<ElasticsearchRecord> TopDocs { get; set; } | ||
public IList<ElasticsearchRecord> TopDocs { get; set; } | ||
|
||
public List<ElasticsearchRecord> Fields { get; set; } | ||
public IList<ElasticsearchRecord> Fields { get; set; } | ||
|
||
public long Count { get; set; } | ||
} | ||
|
||
public class ElasticsearchRecord | ||
{ | ||
public Dictionary<string, object> Data { get; set; } | ||
public JsonObject Value { get; } | ||
|
||
public IReadOnlyDictionary<string, IReadOnlyCollection<string>> Highlights { get; set; } | ||
|
||
public double? Score { get; set; } | ||
|
||
public ElasticsearchRecord() | ||
{ | ||
} | ||
|
||
public ElasticsearchRecord(Dictionary<string, object> data) | ||
{ | ||
Data = data; | ||
} | ||
|
||
public bool TryGetDataValue(string key, out object value) | ||
{ | ||
if (Data == null) | ||
{ | ||
value = null; | ||
|
||
return false; | ||
} | ||
|
||
return Data.TryGetValue(key, out value); | ||
} | ||
|
||
public bool TryGetDataValue<T>(string key, out T value) | ||
public ElasticsearchRecord(JsonObject value) | ||
{ | ||
if (Data == null) | ||
{ | ||
value = default; | ||
|
||
return false; | ||
} | ||
|
||
if (Data.TryGetValue(key, out var obj)) | ||
{ | ||
if (obj is T typedValue) | ||
{ | ||
value = typedValue; | ||
|
||
return true; | ||
} | ||
|
||
if (typeof(T) == typeof(string)) | ||
{ | ||
value = (T)(object)obj?.ToString(); | ||
|
||
return true; | ||
} | ||
|
||
// Handle nullable types (e.g., Nullable<T>). | ||
if (Nullable.GetUnderlyingType(typeof(T)) != null) | ||
{ | ||
// If the object is null, assign the default value for the nullable type. | ||
if (obj == null) | ||
{ | ||
value = default; | ||
|
||
return true; // Return true for null values if T is nullable. | ||
} | ||
} | ||
|
||
try | ||
{ | ||
value = (T)Convert.ChangeType(obj, typeof(T)); | ||
|
||
return true; | ||
} | ||
catch | ||
{ | ||
} | ||
} | ||
|
||
value = default; | ||
ArgumentNullException.ThrowIfNull(value); | ||
|
||
return false; | ||
Value = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters