Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

faceted search using node-solr

Tags:

node.js

solr

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

like image 826
ali haider Avatar asked Apr 12 '12 22:04

ali haider


People also ask

What is SOLR faceted search?

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.

How do you facet in SOLR?

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.

What is facet query?

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.


1 Answers

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!

like image 72
Ajay Pal Singh Avatar answered Oct 16 '22 19:10

Ajay Pal Singh