meteor-reactive-aggregate icon indicating copy to clipboard operation
meteor-reactive-aggregate copied to clipboard

Aggregate and filter with full text indexes

Open bprinsloo opened this issue 5 years ago • 1 comments

Maybe I am missing something, but I can't get the $lookup to work with full text searches. I have a profile object which is a one to one to the users object (Decided to extend it). To pull in the in the users it seems aggregate was the most obvious choice. I want to use the following find in the aggregate:

profile.find(
        { $text: {
            $search: query
          }
        },
        {
          fields: {
            score: {
              $meta: 'textScore'
            }
          },
          sort: {
            score: {
              $meta: 'textScore'
            }
          }
        }
      );

An aggregate without the text query work. But using the above in an aggregate using the property observeSelector get "unknown operator: $text". I think my search translation into the aggregate might be faulty.

bprinsloo avatar May 21 '20 09:05 bprinsloo

I solved it in the end. My publish function use it as follows:

ReactiveAggregate(this, profile, [
          {$match: {
            $text: {
              $search: query
            }
          }            
        }
        ,
          {            
            $lookup: {
                from: "users",
                localField: "__userid",
                foreignField: "_id",
                as: "users"
              }
            }],
            {
              fields: {
                score: {
                  $meta: 'textScore'
                }
              },
              sort: {
                score: {
                  $meta: 'textScore'
                }
              } 
            }
            )

bprinsloo avatar May 22 '20 08:05 bprinsloo