Rocket.chat: Include emoji reaction results in searches

Created on 2 Dec 2016  ·  2Comments  ·  Source: RocketChat/Rocket.Chat

Feature request, use case as per 18F's "Using emoji for knowledge sharing" post.

  • ☑️ can search for emoji
  • ☑️ can respond to a message with an emoji
  • 🔲 search results include messages "tagged" with emoji search term
  • ❓ search results should be agnostic about whether a literal emoji or a Rocket.chat :emoji: shortcode was entered

Tested on demo.rocket.chat @ 0.47.0-develop today, and I see results when searching for emoji, but I do not see expected search results if the emoji is in a user reaction.

I'm very new to Rocket.chat so the error could be user-side 😉

Planned message search

Most helpful comment

OK. So far I've learned a few interesting things and discovered that Rocket.chat seems very easy to hack on - really impressed I could start to make changes so quickly on an unfamiliar stack.

I see that search is implemented in server/methods/messageSearch.js

Aim: I want to be able to search for :evergreen_tree: and see results where that emoji is used in either the message body or a reaction.

I can obtain some of the results I want with reaction matches via this query filter -

db.getCollection('rocketchat_message').find({ 'reactions.:evergreen_tree:': {'$exists': true} })

And I want to include these matches alongside emoji used in messages, which will use this filter -

db.getCollection('rocketchat_message').find({ '$text': { '$search': ':evergreen_tree:' } })

But using an $or doesn't do what I want, possibly because of this requirement: _If $or includes a $text query, all clauses in the $or array must be supported by an index._

What's the best way to compose a query which does this?

db.getCollection('rocketchat_message').find({ '$or': [
  { '$text': { '$search': ':evergreen_tree:' }},
  { 'reactions.:evergreen_tree:': {'$exists': true }}
]})

Other questions at this point:

  • Seems like text search trims non-word chars, so I will also match evergreen_tree as well. Not a major.
  • Seems like text search is stemming, so I unexpectedly matched :grin: alongside :grinning: in the $text results.

All 2 comments

OK. So far I've learned a few interesting things and discovered that Rocket.chat seems very easy to hack on - really impressed I could start to make changes so quickly on an unfamiliar stack.

I see that search is implemented in server/methods/messageSearch.js

Aim: I want to be able to search for :evergreen_tree: and see results where that emoji is used in either the message body or a reaction.

I can obtain some of the results I want with reaction matches via this query filter -

db.getCollection('rocketchat_message').find({ 'reactions.:evergreen_tree:': {'$exists': true} })

And I want to include these matches alongside emoji used in messages, which will use this filter -

db.getCollection('rocketchat_message').find({ '$text': { '$search': ':evergreen_tree:' } })

But using an $or doesn't do what I want, possibly because of this requirement: _If $or includes a $text query, all clauses in the $or array must be supported by an index._

What's the best way to compose a query which does this?

db.getCollection('rocketchat_message').find({ '$or': [
  { '$text': { '$search': ':evergreen_tree:' }},
  { 'reactions.:evergreen_tree:': {'$exists': true }}
]})

Other questions at this point:

  • Seems like text search trims non-word chars, so I will also match evergreen_tree as well. Not a major.
  • Seems like text search is stemming, so I unexpectedly matched :grin: alongside :grinning: in the $text results.

I've implemented a proof of concept / first stab at this, but I don't think it's ready for prime time.

see WIP changes, not submitting a PR as it's not yet ready

I understand that I can't combine $text (index scan) and $exists (collection scan) with an OR. Making a separate query to generate a valid OR query using the results from the first works, and is what I've done to demonstrate here. It may not scale well because it does two queries and could end up passing a lot of _id values back and forth.

Hopefully there is a better approach! Sing-Li recommended I ask in the dev channel during the work week, so leaving this here for now and will check in later :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattlin picture mattlin  ·  3Comments

tanc picture tanc  ·  3Comments

karlprieb picture karlprieb  ·  3Comments

djeber picture djeber  ·  3Comments

antn89 picture antn89  ·  3Comments