Chu Hai
Chu Hai

Reputation: 69

How to use a custom request handler in Solarium

I have set up a request handler /query in solr. Now, when I use this code, it does not work but if I change "query" to "select" it works fine.

// create a client instance
$client = new Solarium\Client($config);


// create a select query instance
$query = $client->createQuery('query'); // change query to select and it works fine

Please let me know. I have tried to search a few hours but there is no answer.

Upvotes: 1

Views: 512

Answers (2)

Adnan
Adnan

Reputation: 97

Just use $select array

$select = array(
   'handler'       => 'yourCustomRequestHandler',
   'start'         => 0,
   'rows'          => 10,
);

// create a select query instance
$query = $this->client->createSelect($select);

Another options check Building a select query

Upvotes: 1

Chu Hai
Chu Hai

Reputation: 69

I have fixed it. I used this

// create a select query instance
$query = $client->createSelect();
$query->setQuery('bird');

// manually create a request for the query
$request = $client->createRequest($query);
$request->setHandler('query');

So, the result of URI is:

Request URI: query?omitHeader=true&wt=json&json.nl=flat&q=bird&start=0&rows=10&fl=%2A%2Cscore

Upvotes: 1

Related Questions