I am using Lucene search. I have a search query. It searches the products in a category. I need the search to return the products in the same order it is ordered inside the category
It works fine when testing with similar code (see below). If you debug, is the sorting being applied correctly? Does it make a difference if you rebuild the index?
var searchQuery = new SearchQuery();
var products = new List<Litium.Web.Models.Products.ProductModel>();
searchQuery.CategorySystemId = Guid.Parse("76930397-9a9e-4b14-8b7a-5520ccb4a1b7");
searchQuery.SortBy = SearchQueryConstants.Recommended;
searchQuery.PageNumber = 1;
searchQuery.PageSize = 100000;
var response = _productSearchService.Search(searchQuery, searchQuery.Tags, true, true, true);
if (response.Hits != null)
{
products.AddRange(_productSearchService
.Transform(searchQuery, response)
.Items
.Value
.OfType<ProductSearchResult>()
.Select(x => x.Item));
}
var articles = products.Select(x => x.SelectedVariant.Id);
Please, check the log-file (not Event log in back office) to see the real lucene.net queries where also the sort information is included. The sort for products in a category should have a sort field like category-{categorySystemId}-sortindex, if that not is the first selection in the sort fields the sorting on the query is not applied correctly.