-
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
5fc7396
commit 620f75c
Showing
10 changed files
with
239 additions
and
96 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
93 changes: 93 additions & 0 deletions
93
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
namespace OrchardCore.Search.Elasticsearch; | ||
|
||
public class ElasticsearchResult | ||
{ | ||
public List<ElasticsearchRecord> TopDocs { get; set; } | ||
|
||
public List<ElasticsearchRecord> Fields { get; set; } | ||
|
||
public long Count { get; set; } | ||
} | ||
|
||
public class ElasticsearchRecord | ||
{ | ||
public Dictionary<string, object> Data { get; set; } | ||
|
||
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) | ||
{ | ||
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; | ||
|
||
return false; | ||
} | ||
} |
8 changes: 0 additions & 8 deletions
8
src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Models/ElasticsearchTopDocs.cs
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.