2

I'm looking for the Redisearch equivalent of the following query:

NOT (topic_id = '123' AND post_id <= '456')

I tried the following - it works but doesn't look like the most elegant solution:

-(@topic_id:[123 123] @post_id:[-inf 456])

topic_id and post_id are NUMERIC and SORTABLE

Thanks for your help!

Amin Golmahalleh
  • 3,585
  • 2
  • 23
  • 36
J. Chris
  • 21
  • 2

1 Answers1

3

Chris, Your query looks perfectly valid, the only simplification I would apply is:

-(@topic_id:123 @post_id:[-inf 456])

To avoid repeating the 123 value. The other option would be to use DeMorgan's law and rewrite your NOT(A AND B) to (!A OR !B) but I don't think that would buy you anything, and in this case it would make it harder to read I think.

BSB
  • 1,516
  • 13
  • 14
  • 1
    Ok so if topic_id is NUMERIC I can do @topic_id:123 and it won't find 1234 etc.? Thanks for your help! – J. Chris May 17 '21 at 16:29