Вопрос

If i run the 2 peices of code to get Sphinx results:

One in PHP:

$host = \Config::get('sphinxsearch::host');
$port = \Config::get('sphinxsearch::port');
$s = new \Sphinx\SphinxClient();
$s->setServer($host, $port);
$sql = "SELECT * FROM essays,posts LIMIT  1, 15;";
var_dump($s->query( $sql, "essays,posts" ));

Returns : 5 rows with a total count of 5 rows (which is wrong)

And then in SSH:

mysql -h0 -P9306
SELECT * FROM essays,posts LIMIT  1, 15

Returns : 15 rows with a total count of 3514 rows (which is correct)

The MySQL window does the "essays,posts" correctly. But using SphinxClient::query does not. If i do just FROM essays in SphinxClient::query its fine.

I've looked around and can find very little on this.

Im using Sphinx 2.1.7

Thank you!

Это было полезно?

Решение

Umm, SphinxClient class is for SphinxAPI . You pass the query() function a full text search directly. NOT a SQL statement.

When you run

 $sql = "SELECT * FROM essays,posts LIMIT  1, 15;";
 var_dump($s->query( $sql, "essays,posts" ));

You are looking for documents that contain the words 'select', 'from', 'essays', 'posts', 'limit', '1' and '15'. Only documents containing ALL those words will be returned - you must have 5 documents with all those words.

To get all documents, sort of your example $sql, you would use

$s->setLimits(1,15);
var_dump($s->query( "", "essays,posts" ));

If you want to query sphinx via SphinxQL syntax, which sort of mimics mysql, then you need to use a MySQL client in your code - NOT Sphinx

Client. ie use mysqli, pdo etc, to run queries.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top