XF 2.2 XF\Search\Query\Query - I want to limit to specific node_ids

Scandal

Well-known member
I'm working on an addon which uses Search (with Elastic Search).
This addon refers to two content types: thread and resource.

How could I limit the results to specific node_ids and specific resource_category_id, without breaking the results?

I guess with something like $query->withSql(new \XF\Search\Query\SqlConstraint()); but my knowledge of Search Core is limited. :)
 
They are indexed so you don't need to use SQL constraints:

PHP:
$query->withMetadata('node', $nodeIds);

PHP:
$query->withMetadata('rescat', $resourceCategoryIds);

Note that you can't combine them as the constraints are boolean "and" and so you would get no results.
 
Thanks for the solution! Is there any way to combine both with OR? Maybe by not using the Metadata method?
 
Not really in the core as it stands, I'm afraid. It's technically possible to extend XFES itself with more comprehensive support for boolean constraints, but it's not exactly simple or straight-forward.
 
Well, I randomly discover that if you try to do the opposite (excluding nodeids and xfrm category ids), by applying the third parameter to 'none' ($match), it works without breaking the results, combined! It makes search in both content types simultaneously. (y)
PHP:
$query->withMetadata('node', $nodeIds, 'none');
PHP:
$query->withMetadata('rescat', $resourceCategoryIds, 'none');

Declaration:
PHP:
public function withMetadata($name, $value = null, $match = 'any')
 
Last edited:
Top Bottom