简体   繁体   中英

Filter search by tags with python redisearch client

I have an index with a TagField, created like this

create_index([TextField("enc_id"), TextField("title", 2.0), TagField("tags")])

I would add a document like this.

add_document(title = "meh, lol", tags = "python,C")

I search like this. It has a few fields that don't need to be searched, so I limited fields to search.

Query(query_string='meh').limit_fields(title)

What I want is to also filter results by some tags. For example, I have documents with tags like python, C, Java and I only want documents to be returned that has the tag 'C'.

How do I do that?

Finally found it:D.

I basically tried to execute pure redis-cli commands with the python client. Didn't know how:/

But this worked. I can use @ in the query string. Just like we do in cli.

Query("@title:meh @tags:{java}")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM