I have the same issue tried various different things but no luck I have essentially adapted the ezSearch for my purpose and all that is remaining is the order by please help:
Query builder:
// Perform the search
var searcher = ExamineManager.Instance.CreateSearchCriteria();
var query = searcher.NodeTypeAlias("umbPropertyDetails");
query.Not().Field("umbracoNaviHide", "1");
// Set search path
var contentPathFilter = model.RootContentNodeId > 0
? string.Format("__IndexType:{0} +searchPath:{1} -template:0", UmbracoExamine.IndexTypes.Content, model.RootContentNodeId)
: string.Format("__IndexType:{0} -template:0", UmbracoExamine.IndexTypes.Content);
var mediaPathFilter = model.RootMediaNodeId > 0
? string.Format("__IndexType:{0} +searchPath:{1}", UmbracoExamine.IndexTypes.Media, model.RootMediaNodeId)
: string.Format("__IndexType:{0}", UmbracoExamine.IndexTypes.Media);
// Ensure page contains all search terms in some way
if (model.Location != "any")
{
query.And().Field("regionID", model.Location);
}
if (model.MinPrice >= 0 && model.MaxPrice > 0)
{
var paddedLower = model.MinPrice.ToString("D6");
var paddedHigher = model.MaxPrice.ToString("D6");
//groupedOr.AppendFormat(String.Format(searchField + ":[{0} TO {1}]", model.MinPrice, model.MaxPrice));
query.And().Range("price", paddedLower, paddedHigher, true, true);
}
if (model.MinBedrooms > 0)
{
query.And().Field("propertyBedrooms", model.MinBedrooms.ToString());
}
var results = ExamineManager.Instance.Search(query.Compile())
.Where(x => (
!Umbraco.IsProtected(int.Parse(x.Fields["id"]), x.Fields["path"]) ||
(
Umbraco.IsProtected(int.Parse(x.Fields["id"]), x.Fields["path"]) &&
Umbraco.MemberHasAccess(int.Parse(x.Fields["id"]), x.Fields["path"])
)) && (
(x.Fields["__IndexType"] == UmbracoExamine.IndexTypes.Content && Umbraco.TypedContent(int.Parse(x.Fields["id"])) != null) ||
(x.Fields["__IndexType"] == UmbracoExamine.IndexTypes.Media && Umbraco.TypedMedia(int.Parse(x.Fields["id"])) != null)
))
.ToList();
model.AllResults = results;
model.TotalResults = results.Count;
model.TotalPages = (int)Math.Ceiling((decimal)model.TotalResults / model.PageSize);
model.CurrentPage = Math.Max(1, Math.Min(model.TotalPages, model.CurrentPage));
// Page the results
model.PagedResults = model.AllResults.Skip(model.PageSize * (model.CurrentPage - 1)).Take(model.PageSize).OrderBy(r => r.Fields["price"]);
LogHelper.Debug<string>("[ezSearch] Searching Lucene with the following query: " + query.ToString());
Sorting search results with Linq is not how you should be sorting anything that comes from Examine.
In Examine's query structure, it has an OrderBy clause which tells Lucene to order by, if you are ordering by in Linq that means it's going to load all search results into memory and perform poorly
Hi thank you for coming back to me however how would I order a list of properties in my scenrio without knowing their prices first? I am searching against a doc type and tried implementing the below can you advise?
// Perform the search
var searcher = ExamineManager.Instance.CreateSearchCriteria();
var query = searcher.NodeTypeAlias("umbPropertyDetails");
if (!string.IsNullOrEmpty(model.SortOrder))
{
switch (model.SortOrder)
{
case "price-low":
query.And().Field("price", "myValue???").And().OrderBy("customfield???");
break;
case "price-high":
query.And().Field("price", model.MaxPrice.ToString("D6")).And().OrderByDescending("price");
break;
default:
query.And().Field("price", model.MinPrice.ToString("D6")).And().OrderBy("price");
break;
}
}
Ez Search sorting results
I have the same issue tried various different things but no luck I have essentially adapted the ezSearch for my purpose and all that is remaining is the order by please help:
Query builder:
Tried solution 1 adding to the query:
Tried Solution 2 append to the results:
And Solution 3 in contentResult Helper
Sorting search results with Linq is not how you should be sorting anything that comes from Examine.
In Examine's query structure, it has an OrderBy clause which tells Lucene to order by, if you are ordering by in Linq that means it's going to load all search results into memory and perform poorly
https://github.com/Shazwazza/Examine/wiki/Sorting-results
Hi thank you for coming back to me however how would I order a list of properties in my scenrio without knowing their prices first? I am searching against a doc type and tried implementing the below can you advise?
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.