In terms of native functionality you're out of luck.
You can do something like this though by rolling your own.
- Manually sort your collections by vendor rank
- Limit your search to collection results by creating your own search function
or
- creat your own search function but make it a "filter" on your current collection and leave the native search alone.
Create Your Own Search:
- Put your item results cell in a snippet. collection-product.liquid
- Include that snippet in
your collecton liquid.
- Make a new collection template
(collection.search-results.liquid)
collection.search-results.liquid looks something like the following. Your pagination size should match the pagination size of your main collection.
{% layout none %}
{% paginate collection.products by 50 %}
<div class="search-results">
{% for product in collection.products %}
{% include 'collection-product' %}
{% endfor %}
</div>
{% endpaginate %}
Now your search becomes an input box with some javascript. The fun part. The script below was pulled from a working site. I've trimmed it up somewhat to hopefully make the bones of it clearer but it probably won't run as is. I've removed references to adding a search because for your purposes you want the native custom search.
As to why not just sort the results. You could use this concept to do that but it returns results a page at a time. In order to custom search all the results you'd have to accumulate the results and sort them when the search is finished. Search time then depends heavily on the size of the collection and the user's network speed.
var defaultView = $(".filters-off"); // add this class to your main collection wrapper
var facetView = $("#filter_target"); // <div id="filter_target"></div> below your main collection wrapper
var currentRequest = 0;
function filterCollection(term){
//[[t1, t2], [t3,t4]]
// console.log('applying '+ JSON.stringify(facets));
var anyResults = false;
var resultsPage=0;
var PAGE_SIZE = 50;
var productsFound = 0;
var collectionPath = location.pathname;
console.log('get from '+ collectionPath);
currentRequest = new Date().getTime();
var viewLink = collectionPath+'?view=search-results'; // same as your layout none template
function applyFilter(myRequest){
resultsPage++;
if(resultsPage > 20) return false; // arbitrary abort for too many results
if(resultsPage > 1) viewLink+='&page='+resultsPage;
return $.get(viewLink).then(function(page){
if(currentRequest != myRequest){
console.log('mid abort');
return false;
}
var pageProducts = $("div[data-tags]", page); //some markup you added to collection-product snippet to help plucking the product elements
if(!pageProducts.length) return false;
console.log('found: '+ pageProducts.length);
var filteredProducts = pageProducts.filter(function(){
if($(this).text().indexOf(term) != -1) return true; // search the returned text
if($(this).attr('data-keywords').indexOf(term) != -1) return true;
return false;
});
if(filteredProducts.length){
if(!anyResults){
anyResults = true;
toggleView(true);
}
filterView.append(filteredProducts);
productsFound+= filteredProducts.length;
}
return (pageProducts.length == PAGE_SIZE && currentRequest == myRequest) ? applyFilter(myRequest) : false;
}).then(function(proceed){
if(currentRequest == myRequest){
if(!anyResults){
toggleView(false, true);
}
}
});
}
applyFilter(currentRequest);
}
function toggleView (showFacets, showNoGo){
facetView.empty();
$(".filter-progress").empty();
if(showFacets) {
defaultView.add('.pagination').hide();
}else {
if(!showNoGo){
defaultView.add('.pagination').show();
}else {
$(".no-facets").clone(true).appendTo(facetView).show(); // .no-facets is normally hidden chunk that allows for easy internationaliztion of "No results found" type messages
}
}
};
{% assign foo = search.results | map: 'item' | sort: 'barcode' %}
? Themap
filter will reduce the search.results to just an array of items, which should then be sortable with the sort filter... – Dave B