I have created one custom product attribute(bestseller). Now I want to sort by custom product attribute(bestseller) using search criteria builder sort by option but it's not working for custom product attribute. FYI Sort by option working with price attribute but not working with custom product attribute option. Any help appreciate...
//Code for fetch products based on search term.
$limit = $this->scopeConfig->getValue('catalog/frontend/list_per_page');
$p = $p?$p:1;
$pageSize = $limit?$limit:20;
$this->_storeManager->setCurrentStore($storeid);
$search_criteria = $this->searchCriteriaBuilder->create();
$search_criteria->setRequestName("quick_search_container");
$search_criteria->setCurrentPage($p);
$search_criteria->setPageSize($pageSize);
$filter = $this->filterBuilder->setField('search_term')
->setValue($q)
->setConditionType("like")
->create();
$filterGroup = $this->filterGroupBuilder->addFilter($filter)->create();
$search_criteria->setFilterGroups([$filterGroup]);
$sortOrder = $this->sortOrderBuilder->setField('bestseller')->setDirection(SortOrder::SORT_DESC)->create();
$search_criteria->setSortOrders([$sortOrder]);
$search_result = $this->searchInterface->search($search_criteria);
$totalSearchResults = $search_result->getTotalCount();
$products = $search_result->getItems();