doukoumi3389 2012-05-05 01:17
浏览 93
已采纳

在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 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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog