It is possible to set a filter/condition in the sphinx api to add an 'AND' condition to the config select? (or to act like an 'AND' condition) ?
SetFilter
doesnt work as I expected, because I'm using sql_attr_multi
, it creates an array with found matches...and the sort defined attributes are overwritten by the newest ones.
If I set 'AND condition' in the config select it works properly, but I need to use it dinamically.
Or maybe to use the sql_query
in php to set the conditions dinamically?
OR setSelect ("*, AND condition")
Edit
I have 3 tables
-companies table
-projects table
-companies_projects table (company id, project_id, company_package)
The same company could be on multiple projects.
The company package could be different on every project (for sorting).
sql_attr_multi = uint project from query; SELECT company_id, project_id FROM companies_projects
It finds the right companies but if the company is on multiple projects, the project attr becomes (8, 10).
On project no. 8 - the package is 2,
On project no. 10 - the package is 1
I apply the filter
$sphinxClient->setFilter('project', array(8));
The problem is that the company_package is overwritten by the last entry (in the database) and I don`t know why.
So the company_package
for project no. 8 should be 2, I`m getting 1 instead, witch is the package for project no. 10.
If I add WHERE project_id = '8'
in sql_query
is working fine, but I need a dynamic solution so I don`t need to create a config file for every project
Edit:
sql_query = \
SELECT \
id, company, \
company_package, UNIX_TIMESTAMP(date) AS date \
FROM companies AS c \
INNER JOIN companies_projects AS cp ON c.id = cp.company_id
companies table: id, company
companies_projects: project_id, company_id, company_package, date
Edit
[1] => Array
(
[weight] => 1
[attrs] => Array
(
[company_package] => 2
[date] => 1367224201
[project] => Array
(
[0] => 8
)
)
)
[2] => Array
(
[weight] => 1
[attrs] => Array
(
**[company_package] => 1** it should be 2
[date] => 1367224202
[project] => Array
(
[0] => 8
[0] => 10
)
)
)
I atached an example. It finds the right companies.
The first key is ok because the company no. 1 is just on project no.8
The second key is not good because the company no. 2 is on both no. 8 and 10 projects like this:
company 1, project 8, package = 2
company 2, project 8, package = 2
company 2, project 10, package = 1
So, the companies are ok, but the package is overwriten from the company 2, project 10, package = 1 If I delete this record...or if I add AND project_id=8 everything is ok