How can ElasticSearch be used to implement social search?

后端 未结 5 671
猫巷女王i
猫巷女王i 2021-01-30 03:15

I’m trying to create a business search with social features using ElasticSearch. I have a business directory, and users can interact with those businesses in different ways: b

5条回答
  •  逝去的感伤
    2021-01-30 04:14

    Solr can do this with the GraphQuery operator.

    https://issues.apache.org/jira/browse/SOLR-7543

    It allows you to put documents in your index that contain a field for the "node_id" and a (multivalued) field for the "edge_id"

    There are a few ways to structure this:

    1. You can have a user document with a list of friend ids on it. Or
    2. You can have a separate table that is a link table that links between user records.

    For case 1: Index a document for each user in the system with a field containing the "user_id" and another field containing "friend_ids".

    At that point to do a search for all friends for user 555 would be:

    {!graph from="user_id" to="friend_ids" maxDepth=1}user_id:555
    

    To find friends of friends of the user

    {!graph from="user_id" to="friend_ids" maxDepth=2}user_id:555
    

    If you have other metadata fields on the user records such as a location field you could add that as a traversal filter to find my friends that live in Boston. This traversal filter is applied to each hop.

    {!graph from="user_id" to="friend_ids" maxDepth=2 traversalFilter="location:Boston"}user_id:555
    

    The above query would find the friends that live in Boston that are friends User 555's that live in Boston.

提交回复
热议问题