解析 Lucene/SOLR debug.explain.structured xml 输出在 PHP 中


Parsing Lucene/SOLR debug.explain.structured xml output in PHP

solr调试模式解释功能的默认"人类可读"格式是完全无用的。您可以通过传递debug.explain.structured=true来获取一些结构化的xml输出。

但是,它生成的 xml 也不是真正可用的,我需要能够在代码中的其他地方使用此调试信息。

在我重新发明轮子之前,我有两个问题:

1)有谁知道现有的PHP类(或函数)可以解析这个xml并将其转换为有用的对象?(谷歌搜索没有发现任何明显的东西)

2)对于那些熟悉SOLR调试模式的人来说,有没有比解析debug.explain.structured xml更好的方法呢?

(我正在使用 SOLR 3.6)

我正在使用solr-php-client来做这件事。我确实使用正则表达式来解析特定值,但很容易访问调试说明。

例如,以下是我如何从调试解释中提取坐标值:

$client = new Apache_Solr_Service($hostname, $port, $url);
$response = $client->search($q, $offset, $limit, $parameters);
$debug = reset($response['debug']['explain']); // get the first explanation
if (preg_match('#(['d'.]+) = coord'(('d+)/('d+)')#m', $debug, $matches)) {
    $coord = floatval($matches[1]);
    $overlap = intval($matches[2]); // the number of matching keywords
    $max_overlap = intval($matches[3]); // the total number of keywords
}

遇到了同样的问题,并盯着一个 GitHub 项目,用于将 solr 解释解析为对象结构。使用此库,可以从解释输出中计算某个字段的影响:

https://github.com/timoschmidt/php-solr-explain