How can I filter search results using facets in Open Search Server using its RESTFul API?

I'm using the following URL (search field template, my template is named 'search' and I'm proxying /search from Apache to Tomcat): http://domain.com:8080/search/services/rest/index/intranet/search/field/search

The following JSON works:

$json = '
{
    "query": "OSH",
    "start": 0,
    "rows": 10,
    "lang": "ENGLISH"
}';

I have a facet named lang that shows value "en" has 450 documents. So, I tried this (based on renderer functionality):

$json = '
{
    "query": "OSH&fq=lang%3A\\"en\\"",
    "start": 0,
    "rows": 10,
    "lang": "ENGLISH"
}';

It turns out that all the terms in the strings were parsed and added to the query instead:

public 'query' => string '(+title:osh^10.0 +title:fq^10.0 +title:lang^10.0 +title:3a^10.0 +title:en^10.0) title:"osh fq lang 3a en"^10.0 (+titleExact:osh^10.0 +titleExact:fq^10.0 +titleExact:lang^10.0 +titleExact:3a^10.0 +titleExact:en^10.0) titleExact:"osh fq lang 3a en"^10.0 (+titlePhonetic:oS^10.0 +titlePhonetic:fk^10.0 +titlePhonetic:lank^10.0 +(titlePhonetic:a^10.0 titlePhonetic:i^10.0) +(titlePhonetic:en^10.0 titlePhonetic:jen^10.0)) titlePhonetic:"oS fk lank"^10.0 (+content:osh +content:fq +content:lang +content:3a +content:e'... (length=1669)

I'm on Open Search Server 1.53.

有帮助吗?

解决方案

You can filter search by using a filters array in your JSON, as shown here.

For example:

{
    "query": "OSH",
    "start": 0,
    "rows": 10,
    "lang": "ENGLISH",
    "filters": [
      {
        "type": "QueryFilter",
        "negative": false,
        "query": "lang:en"
       }
    ]
}

You will find more information on this page.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top