Sorts products in a category based on how it is sorted in backoffice

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

For sort by i used category_sort_order

But the result i got is not in the same order as in back office

This is the part of frontend result

This is the backoffice product

Litium version: [7.6.1]

Use

SearchQueryConstants.Recommended

as the sort order.


I made the changes for sortby. Still getting the same result. Am i doing something wrong with the code

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);

yields

[
    "637471676729630133-06160106-0000-001",
    "637471676729630133-06160107-0000-001_S",
    "637471676729630133-06160105-0000-001",
    "637471676729630133-02423006_L",
    "637471676729630133-23788284"
]

which matches

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.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.