11

I am working on project where I need to implement SphinxSearch with Cake php. So I am simply trying to use a component and behaviour into it. The link to it, is :-

http://bakery.cakephp.org/articles/eugenioclrc/2010/07/10/sphinx-component-and-behavior

I am requesting Sphinx API like below :

$sphinx = array('matchMode' => SPH_MATCH_ALL, 'sortMode' => array(SPH_SORT_EXTENDED => '@relevance DESC'));

$results = $this->ModelName->find('all', array('search' => 'Search_Query', 'sphinx' => $sphinx));

pr($result);

For above it is working fine ,but when I tried to minimise the response time querying to a particular field of the table (using extended match modes,i.e. SPH_MATCH_EXTENDED2) , Sphinx just fails to output any result. The extended query which I used is given below :-

$sphinx = array('matchMode' => SPH_MATCH_EXTENDED2, 'sortMode' => array(SPH_SORT_EXTENDED => '@relevance DESC'));

$results = $this->ModelName->find('all', array('search' => '@Field_name Search_Query', 'sphinx' => $sphinx));

pr($results);

Can anyone recognise where am I going wrong with it? Please help if I am going wrong some where.

Thanks in advance.

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
Nishant Shrivastava
  • 2,113
  • 3
  • 26
  • 43

2 Answers2

1

As you said ,

Sphinx just fails to output any result.

That means it's an error :

Please check whether you have added the specific field to the indexing by using sql_query

Also check if the field you are searching for is not an attribute
As per the sphinx documentation :

Attributes, unlike the fields, are not full-text indexed. They are stored in the index, but it is not possible to search them as full-text, and attempting to do so results in an error.

ashishmohite
  • 1,120
  • 6
  • 14
1

Btw, when you use EXTENDED2 mode make sure your rank mode is set accordingly.

Edit:

Anyway back to you problem, looking at that component/behavior code you can see right away that no error checking is done whatsoever. Try changing the code a bit so you can at least see the errors and/or warnings.

Component

if(!isset($query['search'])){ 
  $result = self::$sphinx->Query('', $indexes);     
} else { 
  $result = self::$sphinx->Query($query['search'], $indexes); 
}

if ($result === false) {
  // throw new SphinxException();
  die(self::$sphinx->GetLastError());
}
$warn = self::$sphinx->GetLastWarning();
if ($warn) echo $warn;

Behavior

$result=$this->runtime[$model->alias]['sphinx']->search($s);
if ($result === false) {
  die($this->runtime[$model->alias]['sphinx']->GetLastError());
}
$warn = $this->runtime[$model->alias]['sphinx']->GetLastWarning();
if ($warn) echo $warn;

I hope that helps.

Kev
  • 118,037
  • 53
  • 300
  • 385
Tralamazza
  • 316
  • 2
  • 5
  • 1
    @Tralamazza : Friend, I won't be putting the actual fields over there. It's just to make experts over here to understand what I am doing. It's part of my project, So I won't be putting the actual code here. – Nishant Shrivastava May 24 '11 at 05:38
  • 1
    @Tralamazza: Just so you're aware, it's a bit dangerous to write *stupid question* on SO. Quite often someone seems to misunderstand and take it that you're calling the original question stupid and you'll earn a few down votes and/or offensive flags. – Hans Olsson May 24 '11 at 07:48
  • @Tralamazza this would be better served as a comment. – JohnP May 24 '11 at 07:55
  • I'm puzzled about Stackoverflow, I did nor meant NOTHING wrong with my question... but I guess people will just vote down for no apparent reason. – Tralamazza May 24 '11 at 08:04
  • 1
    @Tralamazza - we don't say things like "stupid question" or rant about downvotes in answers. Just answer the question (or not) and "Be Nice". – Kev May 24 '11 at 09:54
  • 1
    @Kev - I wrote that **my** question could be stupid (and not the original poster or his question). What's wrong with that ? Btw deleting a SO account is impossible it seems – Tralamazza May 24 '11 at 10:15
  • @trala - my apologies, the way the diff looked it looked as if you had called the OP's question stupid. Sorry, new on the job here. If you want your account deleted then just email team@stackoverflow.com and they'll arrange for that. – Kev May 24 '11 at 10:40
  • @Tralamazza : I have already put the error handling code there, as I was concerned about it too. I am not using rank mode at all, is it the problem behind it. As the behaviour uses the SphinxApi in it, which is not returning me the appropriate results. But when I tried it through CLI, it returns the exact data which is there. I can not figure out the problem behind it. – Nishant Shrivastava May 25 '11 at 06:29
  • 1
    @Nishant - No errors/warnings ? Try editing **sphinxapi.php** (vendor folder) to print out the **$query** param. Search for the function Query() or AddQuery(). – Tralamazza May 25 '11 at 18:59
  • @tralamazza : yeah I checked it out already, I just logged down the $result variable. In the index od $result;i.e $result['matches'] , the id's of the rows which I am getting from sphinxapi are wrong, but on the other hand I tried the same query on CLI, it just worked perfectly fine. Now the question keeps me bugging is, why this Crap Sphinx API is returning me wrong values. Any ideas..? – Nishant Shrivastava May 27 '11 at 13:04