0

I have a model that looks like this

class Message(db.Model):

    content = db.Column(JSON)

I want to perform a search on that field which contain some JSON fields

normally when I something like this it works

Message.query.filter(Message.content['summary'].cast(Unicode).match(search_term))

Now I want to use or another field if the field summary doesn't exist or is empty

using either with or without casting fails with programming error of types needs to be boolean

Message.query.filter(Message.content['summary'] | Message.content['text+video'].match(search_term)) 

1 Answer 1

1

Thanks to Elmer on the #sqlalchemy IRC channel, the logic was not correct, that's how I should have performed the search

Message.query.filter(Message.content['summary'].cast(Unicode).match(search_term) | Message.content['text'].cast(Unicode).match(search_term))

People who are interested should also follow this link where there is a related question with a better answer SQLAlchemy Text Matching data inside JSON field with UTF-8

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.