jlopez
November 19, 2018, 2:23pm
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”)
avsej
November 19, 2018, 3:11pm
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:
// Conjunction Query, whereby two separate queries are defined and then run as
// part of the search, with only the matches returned by both included in the
// result-object.
function conjunctionQuery(Bucket $bucket) {
$indexName = "travel-sample-index-stored";
$firstQuery = SearchQuery::match("La Rue Saint Denis!!")->field("reviews.content");
$secondQuery = SearchQuery::match("boutique")->field("description");
$query = new SearchQuery($indexName,
SearchQuery::conjuncts($firstQuery, $secondQuery));
$query->limit(10)->highlight(SearchQuery::HIGHLIGHT_HTML);
$result = $bucket->query($query);
printResult("Conjunction Query", $result);
}
jlopez
November 19, 2018, 3:26pm
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.