0

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.

Darren Harley
  • 75
  • 1
  • 18
  • The position of the fllters should not influence the results. Can you develop how they are different from one query to the other ? – EricLavault Jan 21 '21 at 18:10
  • .. and if you want to replicate the query - why not just use the `q` part of your query in the Javascript client as well, instead of reformulating it? – MatsLindh Jan 21 '21 at 20:38
  • I've tried the following code `.q({ManufacturerName:'Ford', RangeModelWithYears: 'Fusion (02-12)'})` but this returned an empty result. – Darren Harley Jan 22 '21 at 10:55

1 Answers1

0

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);
        }
    });
};
Darren Harley
  • 75
  • 1
  • 18