Change FTS match query type operator using PHP SDK


#1

We need to perform a match type FTS query by setting the “operator” parameter to “and”.
The the default “opertator” for match type queries is “or”, but we need to change that to “and”
Using API ther request is like this:

{                 
  "explain": false,
  "fields": [
    "*"
  ],              
  "highlight": {},
   "query": 
  	{
    "disjuncts":[
	   {"match":"wordToSearch1 wordToSearch2 wordToSearch3",
	    "field":"bor_title",
	    "operator":"and"           
	   },
	   {"match":"wordToSearch1 wordToSearch2 wordToSearch3",
	    "field":"bor_description",
	    "operator":"and"
	   }
	 ]
    },
    "sort":["-bor_id"]
}

How could We do this using the PHP SDK?

( We are now using a workarround using queryStrings ; “+bor_title:wordToSearch1 +bor_title:wordToSearch2 +bor_title:wordToSearch3”)


#2

What your query is showing is disjuntion (OR) operation, if you need AND, you must use conjunction.

Have you tried SearchQuery::conjuncts already?

There is an example how to use it in the repository:


#3

Yes, but i am refering to the “match” query type inside disjunct.

 {
  "match":"wordToSearch1 wordToSearch2 wordToSearch3",
  "field":"bor_description",
  "operator":"and"
 }

We want to do something like:
$firstQuery = SearchQuery::match(“La Rue Saint Denis!!”)->field(“bor_description”)->operator(“and”);

The default match operator is “or”, and looks for “La” or “Rue” or “Saint” or “Denis!!”, but we need to change it to “and”, like via api request do.