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

allow exact match for strings #3168

Open
wants to merge 1 commit into
base: 2.11.x
Choose a base branch
from

Conversation

mvenghaus
Copy link
Contributor

Sometimes you are in need to make an exact match instead of like in strings. For example I have a string with values "5", "50". With like I have no possibility to get only the value "5".

@romainruaud
Copy link
Collaborator

Hi @mvenghaus

what's the output of this in the rule form ?

@mvenghaus
Copy link
Contributor Author

german .. but i think you get it ;)

image

@rbayet
Copy link
Collaborator

rbayet commented Mar 13, 2024

Hello @mvenghaus,

Adding the operator is not enough though, one also needs to implement the specific query that must be generated to perform the "IS" operation which is to be intended as "contains this ... AND ONLY THIS".
Otherwise, you will have the exact same "match" query generated by those lines.

The initial idea is probably to perform a "term" query.
The issue is that "string" searchable-only attributes do not have an "untouched" subfield version (like option_text_color.untouched)
of type "keyword" on which you can safely perform it.
So you'll probably need to target the base field of a searchable-only text attribute (like "name") which is of type "text" but has the "keyword" analyzer.

It looks like a query like this works as expected :

{
  "size": 20,
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    },
    {
      "entity_id": {
        "order": "desc",
        "missing": "_first",
        "unmapped_type": "keyword"
      }
    }
  ],
  "from": 0,
  "query": {
      "term": {
          "name": "Joust Duffle Bag"
      }
  }
}

You would need to check that this approach works for all string/text attributes susceptible of appearing in the rules engine either because

  • they are searchable only
  • or they are filterable (we allow it, so meh...) only
  • or they are sortable only
  • or they have "use in promo rules" flag set to yes only
  • any combination of the above

Regards,

PS: As a side note, if you add "is", you should also probably add "is not" as a way to exclude a particular product in the context of a more complex rule.
The negation should be taken care of automatically in the QueryBuilder on those lines.

@mvenghaus
Copy link
Contributor Author

hey @rbayet ,

sorry for the late response!

I've created another pull request, because it combines another issue.

#3230

Regards
Marcus

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

Successfully merging this pull request may close these issues.

3 participants