【问题标题】:Parsing Lucene/SOLR debug.explain.structured xml output in PHP在 PHP 中解析 Lucene/SOLR debug.explain.structured xml 输出
【发布时间】:2012-05-05 01:17:19
【问题描述】:

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

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

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

1) 有谁知道现有的 PHP 类(或函数)会解析这个 xml 并将它变成一个有用的对象? (谷歌搜索没有发现任何明显的东西)

2) 对于熟悉 SOLR 调试模式的人,有没有比解析 debug.explain.structured xml 更好的方法来解决这个问题?

(我正在使用 SOLR 3.6)

【问题讨论】:

  • JSON response writer 可以提供帮助。 PHP 可以将 JSON 干净利落地解析成数组和关联数组。

标签: php xml solr lucene


【解决方案1】:

我正在使用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
}

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多