tags:

views:

68

answers:

2

I have sphinx installed for my search engine, and it works great, but now I'm trying to add a few extra features to the search using setFilter() which should allow me to do WHERE/AND clauses, but whenever I try a search, it returns no results when there should.

This is my working code:

 require_once ( "sphinxapi.php" );
 $cl = new SphinxClient ();
 $cl->SetConnectTimeout ( 5 );
 $cl->SetMatchMode ( SPH_MATCH_BOOLEAN );
 $cl->SetSortMode ( SPH_SORT_EXPR  , "@weight" );
 $cl->SetFieldWeights ( array ( "item_title"=>100, "item_tags"=>99 ) );
 $cl->SetLimits(0, 1000, 1000, 1000);
 $cl->SetRankingMode ( SPH_RANK_PROXIMITY_BM25 );
 $cl->AddQuery( $term, "indexTubelogr" );

Now I want to start searching with QUERY - AND item_site_id = 1. I add:

$cl->SetFilter('item_site_id', 1);

Then i get the following error:

Warning: assert() [function.assert]: Assertion failed in /home/domain.com/sphinxapi.php on line 810

I also tried:

$cl->SetFilter('item_site_id', array(1));

This didn't give an error, but again, no results.

My sphinx.conf looks like:

source srcDomain
{
        type                                    = mysql
        sql_sock                                = /tmp/mysql.sock
        sql_attr_timestamp                      = item_date
        sql_ranged_throttle                     = 0
        sql_query_info                          = SELECT * FROM items WHERE item_id=$id
        sql_query                               = \
                SELECT item_id, item_date, item_runtime, item_title, item_tags, item_site_id FROM items
}
index indexDomain
{
        source                  = srcDomain
        path                    = /opt/sphinx/var/data/domain
        docinfo                 = extern
        mlock                   = 0
        morphology              = stem_en
        min_word_len            = 2
        charset_type            = sbcs
        ignore_chars            = U+00AD
        phrase_boundary         = ., ?, !, U+2026 # horizontal ellipsis
        html_strip              = 0
        preopen                 = 1
}

Can anyone please tell me what I am doing wrong?

I removed sensitive data from the code.

A: 

Could you please try running these commands from the command line:

search -i indexTubelogr myterm
search -i indexTubelogr -f item_site_1 1 myterm

and compare the outputs?

Quassnoi
to be honest with you, i dont know how to run sphinx commands via command line.
Godius
@Godius: just copy and paste the commands (changing `myterm` to your actual search query) :)
Quassnoi
Ok i got the command line thing working.using config file '/opt/sphinx/etc/sphinx.conf'...index 'indexTubelogr': search error: no such filter attribute 'item_site_id'.
Godius
So how can I add the filter attribute 'item_site_id' ?
Godius
A: 

Ok I found the problem in the end. I forgot to set the attribute for item_site_id in the sphinx.conf file.

Then with $cl->SetFilter('item_site_id', array(1)); i pulled the results.

Thanks for all the info!

Godius