question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

wildcard query for searchable acting weird with spaces

See original GitHub issue

Describe the bug

Sample data:

[
  {
    id: 'uuid',
    title: 'auto focus textfield'
  },
  {
    id: 'uuid',
    title: 'auto search label'
  },
  {
    id: 'uuid',
    title: 'auto label reports'
  },
  {
    id: 'uuid',
    title: 'disable auto commit on complete'
  }
]

The query below works fine and returns all the fields data with “auto” in them,

{
  searchMyModel (
    filter: {
      title: {
        wildcard: "auto"
      }
    }
  ) {
    items {
      id
      title
    }
  }
}

But when you start adding spaces:

{
  searchMyModel (
    filter: {
      title: {
        wildcard: "auto focus"
      }
    }
  ) {
    items {
      id
      title
    }
  }
}

I’m expecting this to return:

[
  {
    id: 'uuid',
    title: 'auto focus textfield'
  }
]

but it returned:

[]

as it’s the only one with auto and focus on the title. I tried adding asterisk all over the place, *auto focus, auto focus*, *auto focus*, auto*focus, *auto*focus* but none of them worked.

I’m thinking of it in a way that like %search% operator works in MySQL, I might be thinking about it the wrong way but that’s the functionality we are looking for.

To Reproduce Steps to reproduce the behavior:

  1. Add sample model
MyModel @model @searchable {
  id: ID!
  title: String
}
  1. Insert the sample data seen above.
  2. Execute the queries seen above (aws appsync).
  3. See error

Expected behavior

See above

Screenshots N/A

Smartphone (please complete the following information):

Not particular to any device.

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context

See above.

Sample code

See above.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
quorth0ncommented, Jun 29, 2020

@DavidBrear while not related to this ticket, from what I can tell you will likely run into performance issues for any queries beginning with a wildcard, see: https://www.elastic.co/guide/en/elasticsearch/reference/6.2/query-dsl-regexp-query.html and https://www.elastic.co/guide/en/elasticsearch/reference/6.2/query-dsl-wildcard-query.html

Note: The performance of a regexp query heavily depends on the regular expression chosen. Matching everything like .* is very slow as well as using lookaround regular expressions. If possible, you should try to use a long prefix before your regular expression starts. Wildcard matchers like .*?+ will mostly lower performance.

In order to prevent extremely slow wildcard queries, a wildcard term should not start with one of the wildcards * or ?. The wildcard query maps to Lucene WildcardQuery.

0reactions
github-actions[bot]commented, May 26, 2021

This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Elastic Search wildcard search with spaces - Stack Overflow
I think it has something to do with the spaces as when I try to search "* *" , it gives me no...
Read more >
Does SOSL wildcard (*) work with space characters
A search for mi* meyers finds items with mike meyers or michael meyers. So in your case if you want to search for...
Read more >
wildcard — MongoDB Atlas
The wildcard operator enables queries which use special characters in the search string that can match any character. Character. Description ?
Read more >
How To Use Wildcards in SQL - DigitalOcean
There may be times when you want to search for data entries that contain one of SQL's wildcard characters. In such cases, you...
Read more >
Wildcard query | Elasticsearch Guide [8.5] | Elastic
Roll up or transform your data ... Set up a cluster for high availability ... Wildcard queries will not be executed if search.allow_expensive_queries...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found