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

报告相同问题?

悬赏问题

  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题
  • ¥15 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测