Javascript Solr (facet) query script not working correctly

151 views Asked by At

I'm using solr-client to perform a faceted Solr query, and the result of my javascript solr query script doesn't match what's listed in Solr.

So in Solr, the query I've created is as below. This gives the results I'm after.

enter image description here

And my corresponding javascript facet query script is as below.

exports.list_of_all_car_trims = function(solrPrdCfsClient, callback) {
var carTrimsQuery = solrPrdCfsClient.createQuery()
.q('*:*')
.start(0)
.rows(10)
.matchFilter('ManufacturerName','Ford')
.matchFilter('RangeModelWithYears','Fusion (02-12)')
.facet({
    field:'TrimName',
    mincount:'1'
});
solrPrdCfsClient.search(carTrimsQuery,function(err,obj) {
    if(err) {
        callback(err,null);
    }
    else {
        callback(null, obj.facet_counts.facet_fields);
        console.log(obj.facet_counts.facet_fields);
    }
});
};

However, the result of my javascript query script doesn't match the results from Solr.

I'm presuming I've got the correct filters ('ManufacturerName','Ford' & 'RangeModelWithYears','Fusion (02-12)'), but maybe not in the correct positions within the javascript query script?

Any help would be greatly appreciated. Thanks.

1

There are 1 answers

0
Darren Harley On BEST ANSWER

I thought this might be something 'minor' that I was missing, and it was (although this 'minor' thing was failing my whole test!).

Because my matchFilter criteria included spaces, I needed to add some speech marks around this.

My code below works.

exports.list_of_all_car_trims = function(solrPrdCfsClient, ManufacturerName, RangeModelWithYears, callback) {
    var carTrimsQuery = solrPrdCfsClient.createQuery()
    .q('*:*')
    .start(0)
    .rows(10)
    .matchFilter('ManufacturerName','Ford')
    .matchFilter('RangeModelWithYears','"Fusion (02-12)"')
    .facet({
        on:true,
        field:'TrimName',
        mincount:'1',
    });
    solrPrdCfsClient.search(carTrimsQuery,function(err,obj) {
        if(err) {
            callback(err,null);
        }
        else {
            callback(null, obj.facet_counts.facet_fields);
        }
    });
};