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

Query using partial keywords #86

Closed
konsbn opened this issue Dec 31, 2015 · 3 comments
Closed

Query using partial keywords #86

konsbn opened this issue Dec 31, 2015 · 3 comments

Comments

@konsbn
Copy link

@konsbn konsbn commented Dec 31, 2015

Suppose I have a database of books that stores titles, authors etc. Now If I have a book titles "Complex Analysis" I wish the query using "complex" should show up all the matches in the database in this case "COmplex Analysis". I know perhaps this is not the place to ask this but please help me.

@msiemens

This comment has been minimized.

Copy link
Owner

@msiemens msiemens commented Jan 3, 2016

You can search using regular expressions:

>>> db.search(User.name.matches('[aZ]*'))
>>> db.search(User.name.search('b+'))

These correspond to Python's re.match and re.search where the latter searches for an occurenc that may start anywhere in the string.

Alternatively you can use a custom test expression like so:

>>> test_contains = lambda value, search: s.contains(search)
>>> db.search(User.name.test(test_contains, 'Columbia'))

For more details, refer to the relevant section of the TinyDB docs.

BTW: there was a very similar question on StackOverflow.

@msiemens

This comment has been minimized.

Copy link
Owner

@msiemens msiemens commented Jan 20, 2016

@konsbn Does my answer solve your question?

@msiemens

This comment has been minimized.

Copy link
Owner

@msiemens msiemens commented Feb 29, 2016

Closing due to inactivity.

@msiemens msiemens closed this Feb 29, 2016
choyj pushed a commit to choyj/tinydb that referenced this issue Jul 13, 2018
This addresses Issue msiemens#86 allowing the user to perform case-insensitive
matches and searches
msiemens added a commit that referenced this issue Jul 13, 2018
This addresses Issue #86 allowing the user to perform case-insensitive
matches and searches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.