Hi,
i am a user of smart search since it was distributed by its original author Rob Schley as jxFinder and since then missing one important feature - hooking into the query creation process before it is executed to fetch results.
The reason for this wish lies within the limitation of smart search model's query building function. Everything relies on the database fields and there is no evaluation for some fields to be combined via AND OR OR. It is only possible to define this glue in general defaulting to AND, but this sometimes creates where clauses that are not wished.
I integrated a location search for items having a continent id, a country id and a region id. All 3 ids are indexed with every item. The search filters are radiogroups rather than dropdown lists. Now, when it comes to search, the following problem occurs - a user selects:
1. continent 'Europe' (10 indexed items total)
2. countries 'France' (1 indexed item total), 'Austria' (1 indexed item total), 'Germany' (7 indexed items total), 'Ireland' (1 indexed item total)
3. region 'Bavaria' (1 indexed item total)
The expected output would be 4 results:
France + Austria + Bavaria + Ireland
But instead only 1 result will be returned - Bavaria. Why? Because all filters are combined via AND. In other words, the query is:
Select all items that are in Europe AND France AND Austria AND Ireland AND Germany AND Bavaria.
What i really want is:
all items from France + all items from Austria + all items from Ireland + 1 item from Germany.
This extra processing is not part of finders getListQuery function but required for this scenario. So one is forced to hack the core to get the extra processing hooked into the query build.
For this reason i manipulated the getListQuery method to dispatch a new event which is then handled by a smart search plugin - onFinderGetListQuery($context, FinderModelSearch $model, FinderIndexerQuery $query, $sql). This handler, in my case, inspects the FinderIndexerQuery for geo filters selected and then processes the dependencies into the correct relations. Afterwards it removes wrong where statements from the passed in list query and injects the correct ones. When it is done, the query will be returned to be executed.
For me this is the only way to get hands on the query creation process and to inject custom clauses.
I can imagine that there are more scenarios like this that require a possibility to get hands on the query to be executed just before it is executed.
I think, this component should integrate a stage for devs to hook in. So i suggest to integrate the dispatching of this event.
What do you think about this idea?