简体   繁体   English

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

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

The default "human readable" formatting of solr's debug-mode explain feature is completely useless. solr的调试模式解释功能的默认“人类可读”格式完全没用。 You can get some structured xml output by passing debug.explain.structured=true. 您可以通过传递debug.explain.structured = true来获得一些结构化的xml输出。

However the xml it generates isn't really usable either and I need to be able to use this debugging information elsewhere in my code. 但是它生成的xml也不是真的可用,我需要能够在我的代码中的其他地方使用这些调试信息。

Before I re-invent the wheel, I have two questions: 在我重新发明轮子之前,我有两个问题:

1) Does anyone know of an existing PHP class (or function) that will parse this xml and turn it into a useful object? 1)是否有人知道将解析此xml并将其转换为有用对象的现有PHP类(或函数)? (googling didn't turn up anything obvious) (谷歌搜索没有发现任何明显的东西)

2) For those familiar with SOLR's debug mode, is there a better way to approach this than parsing the debug.explain.structured xml? 2)对于那些熟悉SOLR调试模式的人来说,有没有比解析debug.explain.structured xml更好的方法来解决这个问题?

(I'm Using SOLR 3.6) (我正在使用SOLR 3.6)

I am doing this using the solr-php-client . 我正在使用solr-php-client执行此操作。 I do use a regular expression to parse out a specific value, but it's easy to access the debug explanation. 我使用正则表达式来解析特定值,但是很容易访问调试说明。

As an example, here is how I extract the coord value from the debug explanation: 例如,以下是我如何从调试说明中提取coord值:

$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
}

i am having the same problem and stared a github project for parsing the solr explain into an object structure. 我有同样的问题,并盯着一个github项目解析solr解释到一个对象结构。 With this library it is possible to calculate the impact of a certain field from the explain output: 使用此库,可以从解释输出中计算某个字段的影响:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM