Hello everyone, I am thinking of introducing Types...
# community-help
f
Hello everyone, I am thinking of introducing Typesense to a X-like social media app, and trying to remove posts by blocked users from the search result. However,
!
in the query filtering is not working as I expected, and  
"filter_by" : "!$blocks(blocker_user_id := 1)"
and
"filter_by" : "$blocks(blocker_user_id := 1)"
returns the seame result. Can anyone let me know how to solve this? I’m using version 29.0
Copy code
blocks_schema = {
  'name': 'blocks',
  'fields': [
    {'name': 'id', 'type': 'string'},
    {'name': 'blocker_user_id', 'type': 'int32'},
    {'name': 'blockee_user_id', 'type': 'int32'},
  ],
}

posts_schema = {
  'name': 'posts',
  'fields': [
    {'name': 'id', 'type': 'string'},
    {'name': 'name', 'type': 'string', "stem": true},
    {'name': 'description', 'type': 'string'},
    {'name':'created_at', 'type': 'int64'},
    {'name':'created_by', 'type': 'int32', "reference": "blocks.blockee_user_id", "async_reference": true},
  ],
}
j
The filter_by is getting confused because
blockee_user_id
isn't a unique field. What you'd want to do is make a users collection that has a one to many relationship to posts, and also a one to many relationship to blocks. Then you can nest the filter logic in the user->blocks relationship like so:
"filter_by" : "$users(!$blocks(blocker_user_id:=1))"
. I've put up a gist example of how it could work for your example here: https://gist.github.com/YonoYing/73f0de96c0b307e10e33b1a22c4d9dea
f
Thank you very much @Jonathan King !!! Now it's working as I wanted! This is so helpful!