Solr/Solrj分页 [英] Solr/Solrj pagination

查看:237
本文介绍了Solr/Solrj分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将solr和solrj用于我正在创建的Web应用程序中的索引和搜索功能.我的请求处理程序在solrconfig.xml中进行如下配置:

I am using solr and solrj for index and search functionality in a web app I am creating. My request handler is configured in solrconfig.xml as follows:

<requestHandler name="/select" class="solr.SearchHandler">
 <lst name="defaults">
   <str name="echoParams">explicit</str>
   <str name="start">0</str>
   <int name="rows">10</int>
   <str name="defType">edismax</str>
   <str name="qf">
      title^10.0 subtitle^7.0 abstract^5.0 content^1.0 text^1.0
   </str>
   <str name="pf">
      title^10.0 subtitle^7.0 abstract^5.0 content^1.0 text^1.0
   </str>
   <str name="df">text</str>

 </lst>
</requestHandler>

就目前而言,索引和搜索效果很好.但是,我想实现分页.配置文件包含开始"和行"数据.但是,在solrj中,当我运行时:

As it stands, the indexing and searching works well. However, I want to implement pagination. The config file contains "start" and "row" data. However, in solrj, when I run:

SolrQuery query = new SolrQuery(searchTerm);
System.out.println(query.getRequestHandler());
System.out.println(query.getRows());
System.out.println(query.getStart());

三个打印语句均显示为空.我知道每个获取"都有一个对应的集合",但是我可以想象它们已经通过solrconfig.xml中的响应处理程序进行了设置.有人可以告诉我吗?

The three print statements each show null. I understand each of those 'gets' has a correspond 'set', but I would have imagined that they would be already set via the response handler in the solrconfig.xml. Can someone clue me in?

推荐答案

在服务器上执行查询之前,客户端不会知道您在服务器端设置的内容,对吗?因此,它们全为空就不足为奇了.

Before executing the query on the server, the client would not know about what you have set on the server side, right? So it is not a surprise that they are all null.

要实现分页,您需要从客户端获得两个参数-页码和每页的项目数.一旦获得了这两个,就可以在客户端上按以下方式构造SolrQuery:

To implement pagination you need two parameters from the client side - the page number and the number of items per page. Once you got these two, you can construct your SolrQuery on the client side as follows:

SolrQuery query = new SolrQuery(searchTerm);
query.setStart((pageNum - 1) * numItemsPerPage);
query.setRows(numItemsPerPage);
// execute the query on the server and get results
QueryResponse res = solrServer.query(solrQuery);

这篇关于Solr/Solrj分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆