I am trying to confirm whether faceted search is available via node-solr or not. Has anyone used the Solr functionality with nodejs and if so, can you kindly point to an online resource/share sample code that displays the functionality.
Thanks
What Is Faceted Search? Faceted search is the dynamic clustering of items or search results into categories that let users drill into search results (or even skip searching entirely) by any value in any field. Each facet displayed also shows the number of hits within the search that match that category.
Open the web UI of Apache Solr and on the left-hand side of the page, check the checkbox facet, as shown in the following screenshot. On checking the checkbox, you will have three more text fields in order to pass the parameters of the facet search. Now, as parameters of the query, pass the following values.
Facets, also called smart filters, are a type of search filter that are used to help customers narrow down their search results quickly. Unlike static filters that are the same for every search, facets are dynamic — they can change depending on the context of the search query.
Even though I couldn't find it in their official documentation- this is what got working for me.
var client = sails.solr;
var query = client.createQuery().q({
'city_id': options.city_id,
'content_auto': options.term,
})
.fl('sku')
.start(0)
.rows(2000)
.facet({'field':'brand'})
.facet({'field':'price'})
.facet({'field':'discount_percentage'})
.facet({'field':'pack_size'})
.facet({'field':'categories'})
var defer = sails.Q.defer();
client.search(query, function(err, obj){
if(err) {
console.log('Error getting data from solr. Error: ' + err);
return defer.reject(err);
}
return defer.resolve(obj);
});
return defer.promise;
Obviously- stumbled across it by good'ol trial and error!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With