I'm trying to select single rows from sphinx by the primary key "id" but sphinx api outputs nothing and sphinx from command line outputs an error. Instead it works when I search any other field.
I have the primary key "id" than other fields like "remote_id" "title" etc...
Example (not working):
require("sphinxapi.php");
$cl = new SphinxClient;
$cl->setServer("localhost", 9312);
$cl->SetMatchMode(SPH_MATCH_EXTENDED); // or EXTENDED2
$cl->setLimits(0,10);
$query = "@id 5526";
$result = $cl->query($query);
var_dump($result);
Example (working):
require("sphinxapi.php");
$cl = new SphinxClient;
$cl->setServer("localhost", 9312);
$cl->SetMatchMode(SPH_MATCH_EXTENDED); // or EXTENDED2
$cl->setLimits(0,10);
$query = "@remote_id 11964";
$result = $cl->query($query);
var_dump($result);
How can I fetch a specific record (row) by it's primary key?
Can probably use setSelect
to alias it to virtual filter, and then setFilter
on that.
But easier and quicker, can just use SetIDRange
http://sphinxsearch.com/docs/current.html#api-func-setidrange
Rather than
$query = "@id 5526";
$result = $cl->query($query);
would be
$cl->setIDRange(5526,5526);
$result = $cl->query('');