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

在PHP中解析Lucene/SOLR debug.explain.structured xml输出,php,xml,solr,lucene,Php,Xml,Solr,Lucene,solr的调试模式解释功能的默认“人类可读”格式是完全无用的。通过传递debug.explain.structured=true,可以获得一些结构化xml输出 但是,它生成的xml也不是真正可用的,我需要能够在代码的其他地方使用这些调试信息 在我重新发明轮子之前,我有两个问题: 1) 是否有人知道现有的PHP类(或函数)将解析此xml并将其转换为有用的对象?(谷歌搜索没有发现任何明显的问题) 2) 对于熟悉SOLR调试模式的人来说,有没有比解析debug.explain.structured x

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

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

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

1) 是否有人知道现有的PHP类(或函数)将解析此xml并将其转换为有用的对象?(谷歌搜索没有发现任何明显的问题)

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

(我正在使用SOLR 3.6)

我正在使用。我确实使用正则表达式来解析特定的值,但是很容易访问调试说明

例如,下面是如何从调试说明中提取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
}
我正在使用。我确实使用正则表达式来解析特定的值,但是很容易访问调试说明

例如,下面是如何从调试说明中提取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
}

我也遇到了同样的问题,并启动了一个github项目,用于将solr解释解析为对象结构。使用此库,可以从解释输出计算特定字段的影响:


我也遇到了同样的问题,并启动了一个github项目,用于将solr解释解析为对象结构。使用此库,可以从解释输出计算特定字段的影响:

这可能会有所帮助。PHP可以将JSON清晰地解析为数组和关联数组。PHP可以将JSON清晰地解析为数组和关联数组。