Harman Harman - 1 year ago 153
PHP Question

Sphinx search greater than less condition

I want to implement greater than and less than condition in sphinx search

I have one table contain job

id | job_title | min_experience | max_experience
101 | php Developer | 4 | 10
102 | PHP Developer | 6 | 9
103 | PHP Developer | 4 | 5


If user search with 7 year to 8 year experience jobs then 2 (101 and 102) records will display because in these records range are between them. How can I implement this logic on sphinx search. Please if you have an idea share.

There is a setFilterRange range but it will work on one field.

If I will implement this

$sphinx->setFilterRange("min_experience", 7 , 8);
// no result because both are less than 7

$sphinx->setFilterRange("min_experience", 7 , 8);
// no result will display because max experience is 10 or 9


But both records are valid.

Answer Source

Actully think was wrong, this CAN be implemented with normal positive filters

$sphinx->setFilterRange("min_experience", 0 , 7);  //7 is lower user experience
$sphinx->setFilterRange("max_experience", 8 , 900000);  // 8 is the upper upper

This says the matching job, needs between 0 and 7 minimum. The user has 7, so would match any job needing 7 or less. If the user had 5, it would match 101 and 103 as they only need 4, but not 102 as that needs 6.

And the max filter says, 8 or more. The user has 8, so matches 101 and 102, which is ok, as 8 is less than 9/10. Again 103 does not match, as there user has TOO much experience.

(same logic as the previous answer, but avoiding the negative filters so easier to understand!)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download