Hi msiemens
Thanks for commenting. I have tried it again with the following code, which helped me to understand the problem a little bit better:
example.json:
{"_default":
{"1":
{
"url": "https://www.google.com",
"title": "Google",
"contentType": "Web page",
"dateCreated": "2019-11-21"
},
"2": {
"url": "https://www.microsoft.com",
"title": "Microsoft",
"contentType":"Web page",
"dateCreated": "2016-06-08"
}
}
}
Python:
def search_db(query:str):
db = TinyDB('databases/example.json')
q = Query()
result = db.search((q.url.search(query, flags=re.IGNORECASE)) | q.title.search(query, flags=re.IGNORECASE))
return result
This works perfectly for fields that contain strings, but I assume it errors on fields that contain values like 'null', 'true' and 'false'. Because when I run it on the real database, which contains many of these values, I get this error:
File "C:\Users\foprel\AppData\Local\Continuum\anaconda3\lib\re.py", line 183, in search
return _compile(pattern, flags).search(string)
TypeError: expected string or bytes-like object
Although this seems to be an issue with RegEx and not with TinyDB, do you know if there's an easy way to ignore fields with these types of values? Or to search for string values only?