I'm attempting to use Sphinx for the first time in awhile.

require('includes/lib/sphinxapi.php');  // Sphinx Search API
$cl = new SphinxClient();
$cl->SetServer($config['SphinxServer']);
$cl->SetSortMode(SPH_SORT_RELEVANCE);
$cl->SetMatchMode(SPH_MATCH_ANY);
$articles = $cl->Query('Foo', 'articles delta');

If I then do var_dump($articles); it just always returns bool(false). What am I doing wrong?

If, from the CLI on the web server, I do mysql -h <server_name> -P 9306 then it successfully connects and returns queries against 'Foo'.

Update: I just discovered that Query() returns an array on success and false on failure, and if it fails, you can call GetLastError() ... So I did and here's what it told me: connection to server.daniweb.com:0 failed (errno=0, msg=Failed to parse address "server.daniweb.com")

I can connect to the server just fine from the box via CLI?

Update again: OK, got it! I had to manually specify port 9312 as the second parameter of the SetServer() method, since it's apparently not the default port.

I'm happy you work this out!

I'm little bit late, but let me provide few advice on what I see, hope this will help you to go forward with Sphinx and make search faster and more relevant:

  1. You may want to ommit SetServer call at all if you run Sphinx locally on port 9312.

  2. Use SPH_MATCH_EXTENDED instead of SPH_MATCH_ANY. This will enable extended query syntax where you could combine "AND", "OR", "NOT" and other useful operators in the same query (please check http://sphinxsearch.com/docs/current.html#extended-syntax for details) and use custom ranking with per-field weights and internal article popularity.

  3. You may want to combine "articles" and "delta" index under single distributed index. It will make house keeping easier and allow you to shard data without making any changes on application side.

  4. If you want user-generated content to appear in search results promptly you may want to combine ondisk and real-time indexes

  5. Don't forget to add stopword list to remove high-frequency keywords (like "I", "The", "a") from index. This will both decrease index size and speed up queries.

You may also want to take a look on http://bit.ly/SPHXPL12

P.S. Thanks for the DANNIWEB t-shirt! I grabbed one on the Percona Live NY conference past year and still love it :)

commented: Thanks! +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.