Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

property_contains and property_not_contains should use toLower() Cypher string function #424

Open
pmualaba opened this issue May 2, 2020 · 3 comments · May be fixed by #426
Open

property_contains and property_not_contains should use toLower() Cypher string function #424

pmualaba opened this issue May 2, 2020 · 3 comments · May be fixed by #426

Comments

@pmualaba
Copy link

pmualaba commented May 2, 2020

Query

query {
    Product(filter: {name_contains: "iphone"}) {
        id
        type: __typename
        
        name
        isRepresentedAs  {
          rating
          isMany
          timestamp
          Page {
            id
            name
            description
            isRepresentationOf {
              Product  {
                id
                name
              }
            }
          }
        }
    }
}

if my product is stored as "iPhone" or "IPHONE" in the database the above filter is useless...
it is easy to lowercase the searchstring in the application layer but the whole filter is currently implemented case sensitive, which limits its practical usability.
Could the value be wrapped in toLower() cypher string function before applying CONTAINS ?

Thanks for the great work!

@pmualaba pmualaba linked a pull request May 2, 2020 that will close this issue
@johnymontana
Copy link
Member

Hi @pmualaba - this is certainly useful functionality, however wrapping in a toLower() call would mean that an index could not be used for the comparison, which would significantly impact performance for larger datasets. Ideally we can expose this functionality through a fulltext index, which would ensure performant filtering for case insensitive comparisons. We had some thoughts on this in #266

You can accomplish this functionality now by creating a Query field using a @cypher directive.

type Query {
  productContains(searchString: String): [Product] @cypher(statement: """
    MATCH (p:Product)
    WHERE toLower(p.name) CONTAINS toLower($searchString)
    RETURN p
  """
}

See also #261

@ChristiaanScheermeijer
Copy link
Contributor

Hi @johnymontana, we are also having some issues regarding case sensitive search using the _contains filter. The schema we're using is rather large and we are developing a flexible search interface which should be able to search on almost any field.

Would there be any downside by adding a new filter type which uses the regex operator?

For example:

query {
  MusicComposition (filter: { OR: [{ name_like: "(?i)el rossinyol.*" }], [{ creator_like: "(?i)el rossinyol.*" }] })  {
    identifier
    name
    creator
  }
}

Which resolves to the following cypher query:

MATCH (musicComposition:MusicComposition) 
WHERE (musicComposition.name =~ "(?i)el rossinyol.*") OR (musicComposition.creator =~"(?i)el rossinyol.*")
RETURN musicComposition { .identifier , .name, .creator } AS musicComposition

Perhaps like is not the best keyword to prevent confusion/behaviour difference with the SQL like operator.

@michaeldgraham
Copy link
Collaborator

#608

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

Successfully merging a pull request may close this issue.

4 participants