Search code examples
phpamazon-cloudsearch

Can anyone explain me about q vs fq in amazon cloudsearch api version 2013?


endpoint/search?q=shelim&fq=(or (not type:'XYZ') (not mod:'ABC'))&return=_all_fields

My result returns data for type XYZ whereas I have mentioned not to return value for XYZ in the query. Is there anything wrong? Also tell me why q and fq is for?


Solution

  • As it is explained in the Cloudsearch Documentation

    You use the fq parameter to filter the documents that match the search criteria specified with the q parameter without affecting the relevance scores of the documents included in the search results. Specifying a filter just controls which matching documents are included in the results, it has no effect on how they are scored and sorted.

    The q parameter is where you enter your actual query.

    Concerning your data type criteria, you're basically doing

    where type != 'XYZ' OR type != 'ABC'
    

    You need to use an AND condition ((and (not type:'XYZ') (not mod:'ABC'))) so documents which don't have type XYZ and don't have type ABC are filtered out.

    With your query, the documents which have type ABC are filtered out but some of those documents have type XYZ. Those are included since you're using an OR condition.