Testing Queries for CirrusSearch extension
As produced by SimpleKeywordFeature.doApply() (boosting has no effect)
curl -XPOST localhost:9200/wiki_content/_search?pretty -d '
{
"_source": [
"title"
],
"query": {
"bool": {
"must": [
{
"match_all": {}
}
],
"filter": [
{
"bool": {
"should": [
{
"term": {
"title.keyword": {
"value": "Main Page",
"boost": 9
}
}
},
{
"term": {
"title.keyword": {
"value": "Top Page",
"boost": 999
}
}
}
]
}
}
]
}
}
}
'
# from CitolyticsFeature.php
protected function doApply( SearchContext $context, $key, $value, $quotedValue, $negated ) {
$relatedPages = $this->getRelatedPages($context, $value);
// Build bool filter query with related pages (boost by page score)
$filter = new \Elastica\Query\BoolQuery();
foreach($relatedPages as $page) {
$pageFilter = new \Elastica\Query\Term();
$pageFilter->setTerm('title.keyword', $page['title'], $page['score']);
$filter->addShould($pageFilter);
}
return [ $filter, false ];
}
With rewriten MainQuery (boosting works, still can be combined with other filters, e.g. namespace)
curl -XPOST localhost:9200/wiki_content/_search?pretty -d '
{
"_source": [
"title"
],
"query": {
"bool": {
"should": [
{
"term": {
"title.keyword": {
"boost": 1,
"value": "Top Page"
}
}
},
{
"term": {
"title.keyword": {
"boost": 100,
"value": "Main Page"
}
}
},
{
"term": {
"title.keyword": {
"boost": 10,
"value": "Some Page"
}
}
}
],
"minimum_number_should_match": 1,
"filter": [
{
"bool": {
"must": [
{
"terms": {
"namespace": [
0
]
}
}
]
}
}
]
}
}
}'```