doukoumi3389
2012-05-05 01:17 阅读 82

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

The default "human readable" formatting of solr's debug-mode explain feature is completely useless. You can get some structured xml output by passing debug.explain.structured=true.

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.

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? (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?

(I'm Using SOLR 3.6)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    dorpbn1027 dorpbn1027 2012-05-05 01:43

    I am doing this using the 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:

    $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
    }
    
    点赞 评论 复制链接分享
  • dongque20030402 dongque20030402 2013-02-03 18:26

    i am having the same problem and stared a github project for parsing the solr explain into an object structure. 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

    点赞 评论 复制链接分享

相关推荐