使用高级搜索运算符使用 restful API 向搜索引擎发送查询

Using advanced search operators in sending query to saerch engine using restful API

我完全不熟悉 rest API。然而,这些天,我需要使用 ChatNoir Search engine to send some keywords and retrieve related documents. I already write the code to send a query and receive the results. When the query is simple like "hello world", it returns some results but when the number of query terms increases, it returns null. I think the search engine considers the query as an exact match. So, maybe I should use advanced search operators. In the ChatNoir documents 中提供的其余 API,请注意,我们可以像其他搜索引擎一样使用高级搜索运算符。但是,我不知道如何在 JAVA 中使用它。我在查询词之间使用 "And" 运算符并将查询作为字符串发送,但它不起作用。 我的源代码是:

    JSONObject json = new JSONObject();
    json.put("apikey", "$MyAPIKey");
    List<String> datasource=new ArrayList<>();
    datasource.add("cw09");
    json.put("index", datasource);
    json.put("pretty", true);
    json.put("query","hello world");*****

    HttpClient httpClient = new DefaultHttpClient();
    try {
        HttpPost request = new HttpPost("https://www.chatnoir.eu/api/v1/_search");
        StringEntity params = new StringEntity(json.toString());
        request.addHeader("content-type", "application/json");
        request.setEntity(params);
        HttpResponse response= httpClient.execute(request);

        HttpEntity entity = response.getEntity();
        String responseString = EntityUtils.toString(entity, "UTF-8");

        JSONObject jsonObject = new JSONObject(responseString);
        JSONArray jsonArray=null;
        if (jsonObject!=null)
            jsonArray= jsonObject.getJSONArray("results");
            for(int x = 0; x < jsonArray.length(); x++){
            String uuid=jsonArray.getJSONObject(x).getString("uuid");
            String score=String.valueOf(jsonArray.getJSONObject(x).getDouble("score"));
            System.out.print("uuid="+uuid+"\t"+"score="+score);
        }
    } catch (Exception e) {
        System.out.println(e);
    }

因此,问题是如何将查询词发送到搜索引擎而不被视为完全匹配(可能使用高级搜索运算符)。例如查询词为term1,term2,term3,term4,term5,term6.

如有任何帮助,我们将不胜感激。

ChatNoir documantation中提到可以使用不同的Web操作符附加多个关键字。

The simple module is the same module that our end-user web search services uses. That means you can use all operators supported by the web interface (AND , OR, -, "…", site:… etc.) also in your API query string.

搜索引擎不会将您的查询视为完全匹配词组,但默认的术语运算符是 AND,这意味着所有单个术语都必须出现在文档中。精确匹配的短语会受到奖励并出现在单个术语匹配之前,但不是必需的。因此,随着您的查询变长,预计您会得到更少的结果。

如果要搜索仅包含部分查询的文档,则必须将其表述为 OR 查询。例如,"hello world" OR "search engine" 将匹配包含 hello worldsearch engine 或两者的文档。不过,确实希望结果完全不连贯。有时一个术语更为常见并且与更多文档匹配,因此您将很难找到也包含另一个术语的结果。