Solr FieldCollapsing获得更多类似此查询的信息 [英] Solr FieldCollapsing for More Like This queries

查看:79
本文介绍了Solr FieldCollapsing获得更多类似此查询的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用更多类似内容"查询来查找相似的文档,并折叠那些与图像"字段具有相同值的文档.我尝试使用字段折叠参数,但是它们似乎不适用于更多类似这样"的参数.

I want to use a "More Like This" query to find similar documents and collapse those that have the same value for the field 'image'. I tried to use the Field Collapsing parameters however they do not seem to work for "More like this".

下面是我的代码段.您能告诉我如何使用更多类似内容"查询来折叠结果吗?

Below is a snippet of my code. Can you tell me how to collapse results using the "More Like This" query?

$url = "http://{$host}:{$port}/solr/{$core}/mlt";

$data = [
    'stream.body' => $content,
    'fl' => 'image,content,title,signature',
    'start' => 0,
    'order' => "score desc",
    'wt' => 'json',
    'mlt.fl' => 'content,title',
    // these lines do nothing ---v
    'group' => 'true',
    'group.field' => 'image',
    'group.sort' => 'impressions desc',
    'group.main' => 'true'
];

$curlHandle = curl_init($url);

$options = array (
        CURLOPT_POST => 1,
        CURLOPT_POSTFIELDS => $data
);

curl_setopt_array($curlHandle , $options);
$result = json_decode(curl_exec($curlHandle));

推荐答案

一般回答

我无法使用字段折叠"参数折叠结果.但是,我可以使用 CollapsingQParserPlugin 达到所需的结果. 以下过滤查询折叠图像"字段上的文档,并为印象"字段选择值最高的文档:{!collapse field=image max=impressions}

General answer

I could not collapse results using Field Collapsing paramaters. However, I was able to achieve the desired result using CollapsingQParserPlugin. The following filter query collapses documents on the field 'image' and selects the one with the highest value for the field 'impressions': {!collapse field=image max=impressions}

由于某种原因,我无法通过单个键将此过滤器查询与其他过滤器查询结合在一起,如下所示:

For some reason I was not able to combine this filter query with my other filter queries under a single key as follows:

$filterQueries = [
    "-signature:{$signature}",
    ...
    "{!collapse field=image max=impressions}"
];
$data = [
    ...
    'fq' => implode(' AND ', $filterQueries),
    ...
];

这产生了错误:查询未实现createWeight

This produced the error: Query does not implement createWeight

我的解决方法是执行GET请求(而不是在上面的问题中完成的POST).使用GET请求,可以为每个过滤器查询提供一个键:

My fix was to do a GET request (instead of a POST, which was done in the question above). With the GET request it is possible to have a key for each filter query: http://solr-url/mtl?...&fq=-signature%3A0&...&fq=%7B!collapse+field%3Dimage+max%3Dimpressions%7D

下面是问题中代码段的php解决方案:

Below is the php solution for the snippet in the question:

$url = "http://{$host}:{$port}/solr/{$core}/mlt?"; // Note the added question mark

$data = [
    'stream.body' => $content,
    'fl' => 'image,content,title,signature',
    'fq' => $filterQueries,
    'start' => 0,
    'order' => "score desc",
    'wt' => 'json',
    'mlt.fl' => 'content,title'
];

$params = [];
foreach ($data as $key=>$value) {
    if (is_array($value)) {
        foreach ($value as $subvalue) {
            $subvalue = urlencode($subvalue);
            $params[] = "{$key}={$subvalue}";
        }
    } else {
        $value = urlencode($value);
        $params[] = "{$key}={$value}";
    }
}
$url .= implode('&', $params);

$curlHandle = curl_init($url);
$options = array ();
curl_setopt_array($curlHandle , $options);
$result = json_decode(curl_exec($curlHandle));

这篇关于Solr FieldCollapsing获得更多类似此查询的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆