简体   繁体   English

PHP Solr客户端 - 请求实体太大

[英]PHP Solr Client - Request Entity Too Large

I am using SOLR PHP client to query data from a solr service. 我正在使用SOLR PHP客户端从solr服务查询数据。 My code looks similar to the below in that I'm passing in a query to search on multiple IDs (in my case, a lot). 我的代码看起来与下面类似,因为我传递了一个查询来搜索多个ID(在我的情况下,很多)。 The problem arises for me when I'm searching for too many IDs at once. 当我一次搜索太多ID时,问题就出现了。 I get a 'Request Entity Too Large' when passing in too many IDs. 传入太多ID时,我得到“请求实体太大”。 Is there a way to get around this? 有办法解决这个问题吗? From what I see in various examples, the syntax seems to be 'id:1 OR id:2 OR id:3 etc.' 从我在各种示例中看到的,语法似乎是'id:1 OR id:2 OR id:3 etc. when searching on multiple values. 搜索多个值时。 This there a different syntax that would reduce the size of the request being passed into the service? 这有不同的语法可以减少传递给服务的请求的大小? eg In SQL we can say, 'id in (1,2,3,etc.)'. 例如,在SQL中我们可以说'id in(1,2,3,etc。)'。 Can we do something similar for the SOLR query? 我们可以为SOLR查询做类似的事情吗?

<?php  
  require_once( 'SolrPHPClient/Apache/Solr/Service.php' );  
  $solr = new Apache_Solr_Service( 'localhost', '8983', '/solr' );    

  $offset = 0;
  $limit = 10;

  $queries = array(
    'id: 1 OR id: 2 OR id:3 OR id:4 OR id:5 OR id:6 or id:7 or id:8'  // in my case,       this list keeps growing and growing
    );

  foreach ( $queries as $query ) {
  $response = $solr->search( $query, $offset, $limit );

  if ( $response->getHttpStatus() == 200 ) { 
     print_r( $response->getRawResponse() );
  }
  else {
     echo $response->getHttpStatusMessage();
  }
 }
?>

Solr supports searching through POST HTTP requests instead of GET requests which will allow you to have a much bigger query. Solr支持搜索POST HTTP请求而不是GET请求,这将允许您有更大的查询。 I don't know how to enable this in the PHP client you're using. 我不知道如何在您正在使用的PHP客户端中启用它。

However this is only a bandaid. 然而,这只是一个绑带。 The real problem is that you seem to be misusing Solr. 真正的问题是你似乎在滥用Solr。 You will likely run into other limits and performance issues, simply because Solr wasn't designed to do what you're trying to do. 您可能会遇到其他限制和性能问题,因为Solr不是为了做您想做的事情而设计的。 You wouldn't use PHP to write an operating system, right? 您不会使用PHP编写操作系统,对吧? It's the same with this. 这与此相同。

I recommend creating a new question with the real issue you have that led you to run this kind of queries. 我建议使用您所遇到的真正问题创建一个新问题,以便您运行此类查询。

Solr supports range queries, ie id:[1 TO 10], or id:[* TO *] to match all. Solr支持范围查询,即id:[1到10],或id:[* TO *]以匹配所有。 Since it looks like many of your "ORs" are with respect to sequential IDs, this should help. 由于看起来许多“OR”与顺序ID有关,因此这应该有所帮助。

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

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