Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem in implementing Sphinx API along with Cake php

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.

like image 830
Nishant Shrivastava Avatar asked May 23 '11 13:05

Nishant Shrivastava


2 Answers

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.

like image 87
Tralamazza Avatar answered Oct 18 '22 09:10

Tralamazza


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.

like image 27
ashishmohite Avatar answered Oct 18 '22 09:10

ashishmohite