Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4604928
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:21:47+00:00 2026-05-22T00:21:47+00:00

I have Sphinx Search installed as my search engine and I’m trying to add

  • 0

I have Sphinx Search installed as my search engine and I’m trying to add a few extra features to the search using setFilter() and SetSelect() which should allow me to do WHERE/AND clauses. But whenever I try a search, it returns no results instead of results.

Here is my sphinx.conf: http://pastebin.com/M6Kd71u0

And here’s the PHP code:

require("sphinxapi.php");

$host = "localhost";
$port = 9312;
$index = "llgenre";
$select1 = "cartoon";
$label6 = "children";
$type = 4;
$limit = 20;
$ranker = SPH_RANK_PROXIMITY_BM25;
$mode = SPH_MATCH_ALL;

$sphinx = new SphinxClient();
$sphinx->setServer($host, $port);
$sphinx->setConnectTimeout(0);
$sphinx->setMatchMode($mode);
$sphinx->setRankingMode($ranker);
$sphinx->setSelect('*, select1="'.$select1.'" AND label6="'.$label6.'" AS mycond');
$sphinx->setFilter('mycond', array(1));

$res = $sphinx->query($type, $index);

die(var_dump($res));

How can I search by type = 4, filter by select1 with cartoon and finally on label6 with children?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:21:47+00:00Added an answer on May 22, 2026 at 12:21 am

    I believe what you’re attempting to do is to filter strings as attributes. Referring to the Sphinx FAQ, they outline the procedure

    How do I filter, sort, or group by
    string column without string
    attributes?

    You can do all of this, except for
    precise arbtrary-length sorting over
    several indexes.

    To filter and group, you can replace
    the string with an unique numeric ID.
    Sometimes its possible to create a
    lookup dictionary in the database (eg.
    for fixed lists of cities or
    countries), or even use an existing
    one, replace strings with their IDs in
    that dictionary, then filter and group
    on that ID. If not, you can always
    replace the string with its checksum,
    eg. CRC32() or (any) 64 bits taken
    from MD5() at indexing time (no need
    to alter the tables!), store it using
    sql_attr_uint or sql_attr_bigint
    respectively, and then filter or group
    on that checksum attribute.
    (Note that
    there’s a certain chance of CRC32()
    collisions if you have millions of
    strings but practically zero chance of
    MD5() collisions.)

    So, in my sphinx.conf, I might have the following…

    sql_query = SELECT CRC32(string_field) AS `string_field` FROM `table`
    
    sql_attr_uint = string_field
    

    Then in PHP, I would apply a filter on the field like so…

    $sphinx->SetFilter('string_field', array(crc32( 'filter_string' ));
    

    —

    Unfortunately, PHP has an annoying problem(bug?) when converting to crc32… something involving unsigned integers or something..

    I use the following function to convert correctly

    class Encode {
        public static function crc32($val){
            $checksum = crc32($val);
            if($checksum < 0) $checksum += 4294967296;
            return $checksum;
        }
    }
    

    —

    Be careful of character case! You may choose to convert the column to lower case while indexing eg.

    sql_query = SELECT CRC32(LOWER(string_field)) AS `string_field` FROM `table`
    

    and searching…

    $sphinx->SetFilter('string_field', array(crc32(strtolower( 'Filter_String' )));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Wordpress-based website which uses Sphinx as a search engine, with a
I have this sphinx search engine that I use through Zend using sphinxapi.php .
I have sphinx installed for my search engine, and it works great, but now
I'm thinking about using Sphinx as a search engine for my site. But since
I'm using a Sphinx search engine to perform my searches in a Rails project,
im building a search engine with php/sphinx/jquery and i have most of it working
We have a database that we would like to index with Sphinx search engine.
How is that possible to show sphinx search result via PHP i have installed
I have a website that is using Sphinx search server to search through a
I have installed Sphinx in order to document some Python modules and class I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.