繁体   English   中英

如何使用Perl从Apache Solr中的响应获取numFound值

[英]How to get numFound value from response in Apache Solr using Perl

我使用以下代码从Apache Solr搜索文档(内容中具有特定关键字)

my $solrgetapi = "http://$address:$port/solr/OppsBot/select?q=content:";
my $solrgeturl = $solrgetapi.'"'.$keyword.'"';

my $browser = LWP::UserAgent->new;
my $req =  HTTP::Request->new( GET => $solrgeturl );
$req->authorization_basic( "$username", "$pass" );
my $page = $browser->request( $req );
print $page->decoded_content;

我得到的结果如下:

{
"responseHeader":{
"status":0,
"QTime":2,
"params":{
"q":"content:\"ABC\""}},
"response":{"numFound":0,"start":0,"docs":[]
}}

我想将numFound值提取到一个变量。

我在SolrJ中遇到了像这样的一些解决方案

queryResponse.getResults().getNumFound();

但是我在Perl中找不到。

我也尝试了以下代码。 但是我无法使它们起作用。 请帮忙。

$numFound = $page->decoded_content->{response}->{numFound};
print $page->{numFound}

您忽略了将JSON文本转换为数据结构。

use JSON::MaybeXS qw(decode_json);
say decode_json($page->decoded_content)->{response}{numFound}
# 0

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM