Skip to content

Add support for Nested Conditions via AndCondition and OrCondition #433

Merged
alexander-schranz merged 18 commits intoPHP-CMSIG:0.6from
Toflar:feature/and-or-conditions
Oct 10, 2024
Merged

Add support for Nested Conditions via AndCondition and OrCondition #433
alexander-schranz merged 18 commits intoPHP-CMSIG:0.6from
Toflar:feature/and-or-conditions

Conversation

@Toflar
Copy link
Copy Markdown
Member

@Toflar Toflar commented Oct 7, 2024

Started implementing #317.

Works for Meilisearch and Loupe, the others I haven't got any local setup for at the moment 🙈
But maybe this can be a helpful start to push it over the finishing line.


This adds 2 new conditions.

AndCondition

$searchBuilder->addFilter(new Condition\AndCondition($conditionA, $conditionB);

OrCondition

$searchBuilder->addFilter(new Condition\OrCondition($conditionA, $conditionB);

Nested conditions are now possible:

$searchBuilder->addFilter(
    new Condition\AndCondition(
        new Condition\EqualCondition('tags', 'Tech'),
        new Condition\OrCondition(
            new Condition\EqualCondition('tags', 'UX'),
            new Condition\EqualCondition('isSpecial', false),
        ),
    ),
);

@alexander-schranz alexander-schranz added the features New feature or request label Oct 8, 2024
@alexander-schranz alexander-schranz added this to the 1.0.0 milestone Oct 8, 2024
@alexander-schranz alexander-schranz added Adapter: Meilisearch Meilisearch Adapter related issue Adapter: Loupe Loupe Adapter related issue labels Oct 8, 2024
@alexander-schranz
Copy link
Copy Markdown
Member

@Toflar Thank you!

Works for Meilisearch and Loupe, the others I haven't got any local setup for at the moment 🙈

If you want to give it a try a docker-compose.yml exists in every adapters directory if you want to start the service docker compose up is enough. What may very similar to Meilisearch is Typesense Adapter: https://github.com/schranz-search/schranz-search/blob/4267ea93ec459e15df084cd1727457dcbd1a4457/packages/seal-typesense-adapter/src/TypesenseSearcher.php#L77-L114

The only problem if I see currently a Geo based Conditions can not be part of a Nested Conditions. But think that is some edgecase we currently can ignore.

Comment thread packages/seal/src/Search/Condition/AndCondition.php Outdated
@Toflar
Copy link
Copy Markdown
Member Author

Toflar commented Oct 9, 2024

I have updated the conditions so that they are easier to use and they also only accept the supported nested conditions. Typesense is implemented as well now.

For the MemoryAdapter - am I right that this is just for testing purposes? We could just use Loupe with the in-memory configuration - it's been designed for exactly that and then we wouldn't have to develop all that logic with nested comparisons etc.

@alexander-schranz
Copy link
Copy Markdown
Member

I will take care of the memory adapter. At current state I want to keep the memory adapter as it good to have one which don't require any additional dependencies.

@Toflar
Copy link
Copy Markdown
Member Author

Toflar commented Oct 10, 2024

Elasticsearch, Opensearch and Algolia are now also supported. I had to adjust the example because Algolia does not support filtering for ORs of ANDs (algolia/algoliasearch-client-php#385).

@alexander-schranz alexander-schranz marked this pull request as ready for review October 10, 2024 11:32
@alexander-schranz alexander-schranz added Adapter: Elasticsearch Elasticsearch Adapter releated issue Adapter: Opensearch Opensearch Adapter related issue labels Oct 10, 2024
@alexander-schranz alexander-schranz added Adapter: Memory Memory Adapter related issue Adapter: Algolia Algolia Adapter related issue Adapter: Solr Solr Adapter related issue Adapter: Typesense Typesense Adapter related issue Adapter: RediSearch RediSearch Adapter related issue SEAL Core Seal Core related issue labels Oct 10, 2024
@alexander-schranz alexander-schranz changed the title Implemented AndCondition and OrCondition Add support for Nested Conditions via AndCondition and OrCondition Oct 10, 2024
@alexander-schranz alexander-schranz merged commit 94ba580 into PHP-CMSIG:0.6 Oct 10, 2024
@alexander-schranz
Copy link
Copy Markdown
Member

@Toflar Good work, thank you 👍

@Toflar Toflar deleted the feature/and-or-conditions branch October 10, 2024 11:44
alexander-schranz added a commit that referenced this pull request Oct 10, 2024
This add missing docs about the newly added `AndCondition` and
`OrCondition` from
#433 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Adapter: Algolia Algolia Adapter related issue Adapter: Elasticsearch Elasticsearch Adapter releated issue Adapter: Loupe Loupe Adapter related issue Adapter: Meilisearch Meilisearch Adapter related issue Adapter: Memory Memory Adapter related issue Adapter: Opensearch Opensearch Adapter related issue Adapter: RediSearch RediSearch Adapter related issue Adapter: Solr Solr Adapter related issue Adapter: Typesense Typesense Adapter related issue features New feature or request SEAL Core Seal Core related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants