I am using SOLR PHP client to query data from a solr service. 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). The problem arises for me when I'm searching for too many IDs at once. I get a 'Request Entity Too Large' when passing in too many IDs. 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.' when searching on multiple values. This there a different syntax that would reduce the size of the request being passed into the service? e.g. In SQL we can say, 'id in (1,2,3,etc.)'. Can we do something similar for the SOLR query?
<?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开发者_如何学JAVA );
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. I don't know how to enable this in the PHP client you're using.
However this is only a bandaid. The real problem is that you seem to be misusing 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. You wouldn't use PHP to write an operating system, right? 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, i.e. id:[1 TO 10], or id:[* TO *] to match all. Since it looks like many of your "ORs" are with respect to sequential IDs, this should help.
精彩评论