Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v4] Query grouping bug #92

Open
nikobe5545 opened this issue Jul 5, 2024 · 1 comment
Open

[v4] Query grouping bug #92

nikobe5545 opened this issue Jul 5, 2024 · 1 comment

Comments

@nikobe5545
Copy link

nikobe5545 commented Jul 5, 2024

When creating query groups directly after the where-directive the groups are not created correctly, but if adding some dummy filter before adding groups it works as expected (examples below).

Steps to Reproduce

In my case I have a collection of products with name and brand (and some other fields). I have a use-case where I want to search for a tokenised string, for instance "first second" and look for matches in either name or brand for each word in the string.

The idea was to create an Isar query that resembles the following pseudo SQL:

WHERE
(name CONTAINS 'first' OR brand CONTAINS 'first')
AND
(name CONTAINS 'second' OR brand CONTAINS 'second')

The generated query however is equivalent to the following pseudo SQL:

WHERE
name CONTAINS 'first'
OR (
  brand CONTAINS 'first'
  AND (
    name CONTAINS 'second'
    OR brand CONTAINS 'second'
  )
)

Code sample

Code that does not give the expected result:

final result = isar.products
        .where()
        .group((q) => q.nameContains('first').or().brandContains('first'))
        .and()
        .group((q) => q.nameContains('second').or().brandContains('second'))
        .findAll();

Workaround (note the added nameIsNotEmpty()):

final result = isar.products
        .where()
        .nameIsNotEmpty()
        .group((q) => q.nameContains('first').or().brandContains('first'))
        .and()
        .group((q) => q.nameContains('second').or().brandContains('second'))
        .findAll();

In my case it was easy to create the workaround because the name will never be empty, so it's like adding a 1 = 1 in SQL.

Details

  • Platform: moto g(9) plus (XT2087-2), Android
  • Flutter version: 3.22.2
  • Isar version: 4.0.3
@bendangelo
Copy link

This is also happening on v3. I have to add a dummy filter after filter or where.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants