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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!