Debasish
08/22/2023, 5:42 AMD_Inventor
08/22/2023, 6:13 AMcsharp
public ISearchResults GetRelatedItemsForPage(int siteId, string docUrl, int maxResults = 3)
{
ISearchResults results = null;
try
{
IExamineManager examineManager = StaticServiceProvider.Instance.GetService<IExamineManager>();
if (examineManager.TryGetIndex("ExternalIndex", out var index))
{
var query = index.Searcher.CreateQuery("content")
.Field("relatedProfiles", docUrl.Fuzzy())
.And()
.Field("searchPath", siteId.ToString()).And()
.RangeQuery<long>("displayDateForSorting".Split(','), DateTime.Now.AddYears(-2).Ticks, null)
.OrderByDescending(new Examine.Search.SortableField("displayDateForSorting", SortType.Long))
.OrderByDescending(new Examine.Search.SortableField("updateDate", SortType.Long));
results = query.Execute(new QueryOptions(0, maxResults));
}
}
catch (Exception ex)
{
}
return results;
}
Just start with \``` and end with \```D_Inventor
08/22/2023, 6:14 AMMike Chambers
08/22/2023, 9:26 AMcsharp
public static IExamineValue Fuzzy(this string s)
{
return Fuzzy(s, 0.5f);
}
https://github.com/Shazwazza/Examine/blob/release/3.0/src/Examine.Core/SearchExtensions.cs#L44-L47Mike Chambers
08/22/2023, 9:45 AMquery
at run time and see what's been generated, and then test in the backoffice or luke..
You can also update the LuceneDirectoryIndexOptions
for those sortable fields, and then you don't need to mess converting t o Ticks
or specifying SortType.Long
in the sortableFields.
(don't forget to rebuild the index via the backoffice for changes to take effect)
So it becomes
query.And().RangeQuery<DateTime>(new[] { "displayDateForSorting"}, min: DateTime.Now.AddYears(-2), max: null);
and
csharp
query.OrderByDescending(new SortableField("displayDateForSorting"));
query.OrderByDescending(new SortableField("updateDate"));
Mike Chambers
08/22/2023, 9:45 AMDebasish
08/22/2023, 3:10 PMDebasish
08/23/2023, 5:49 AMCategory: "content", LuceneQuery: {+relatedProfiles:umb://document/229816e0e6314de79aed1b8943b91637~0.5 +searchPath:1433 +(displayDateForSorting:[637652963658635555 TO *])}
However the query generated by umbraco v10 site is
Category: "content", LuceneQuery: {+relatedProfiles:umb://document/229816e0e6314de79aed1b8943b91637~2 +searchPath:1433 +(displayDateForSorting:[637652969796493318 TO *])}
As can be seen the fuzzy value is different. Is that the problem? But why is it giving us a different value of 2? Any thoughts?D_Inventor
08/23/2023, 6:21 AMnzdev
08/23/2023, 6:22 AMDebasish
08/23/2023, 6:52 AMDebasish
08/23/2023, 6:53 AMCategory: "content", LuceneQuery: {+(relatedProfiles:umb relatedProfiles:document relatedProfiles:229816e0e6314de79aed1b8943b91637) +searchPath:1433 +(displayDateForSorting:[637652991549190507 TO *])}
D_Inventor
08/23/2023, 6:55 AMD_Inventor
08/23/2023, 6:56 AMD_Inventor
08/23/2023, 6:56 AMnzdev
08/23/2023, 11:21 AMDebasish
08/23/2023, 11:54 AMDebasish
08/23/2023, 11:54 AMpublic ISearchResults GetRelatedItemsForPage(int siteId, string key, int maxResults = 3)
{
try
{
IExamineManager examineManager = StaticServiceProvider.Instance.GetService<IExamineManager>();
if (examineManager.TryGetIndex("ExternalIndex", out var index))
{
var query = index.Searcher.CreateQuery("content")
.Field("relatedProfiles", key.EnsureEndsWith(key))
.And()
.Field("searchPath", siteId.ToString()).And()
.RangeQuery<long>("displayDateForSorting".Split(','), DateTime.Now.AddYears(-2).Ticks, null)
.OrderByDescending(new Examine.Search.SortableField("displayDateForSorting", SortType.Long))
.OrderByDescending(new Examine.Search.SortableField("updateDate", SortType.Long));
results = query.Execute(new QueryOptions(0, maxResults));
}
}
catch (Exception ex)
{
}
return results;
}