0

I'm programming a meteor app and I need some advice in how can I do the following. I have a collection called Articles which it has newspaper articles. My idea is to create a map where every key points to a group of articles that has that word in it's title.

For example:

/* Article 1 */
{
    "_id" : "SB4mKAxaBijQXnS73",
    "title" : "Messi signs new contract with Barcelona"
}
/* Article 2 */
{
     "_id" : "rhqioBkePzGCrRFLp",
     "title" : "Messi is from Argentina"
 }
/* Article 3 */
{
      "_id" : "X6LochRZw32op39W8",
      "title" : "President of Argentina visits Messi"
}

Then I will have:

Messi ==> [Article 1, Article 2, Article 3]
signs ==> [Article 1]
new ==> [Article 1]
contract ==> [Article 1]
with ==> [Article 1]
Barcelona ==> [Article 1, Article 3]

is ==> [Article 2]
from ==> [Article 2]
Argentina ==> [Article 2, Article 3]

President ==> [Article 3]
of ==> [Article 3]
visits ==> [Article 3]

Then I need to only return the tuple (key, array) where:

  • Keyword has more than 3 letters (This I can avoid it if I check the length of the word before using it as a key)
  • Group has more than 1 Article.

My idea then is to iterate over that array and show it in the template, for that reason I need to do it in a template helper.

Santiago Salem
  • 577
  • 2
  • 12
  • You're basically building your own text indexing scheme. Why not just use mongodb text search or something like Algolia? – Michel Floyd Jul 19 '17 at 18:29
  • @MichelFloyd Can you tell me how can I do something like that in mongodb considering the conditions(key with more than 3 words and groups with more than 1 Article)? My idea is to show that groups of articles in a template; and if it is posible to do it with mongodb it will be much easier – Santiago Salem Jul 19 '17 at 19:03
  • Unclear on what you're trying to do. Are you trying to create a list of all the words that are used and then show all the articles that have that word in it? Or triplets of words? – Michel Floyd Jul 19 '17 at 19:16
  • @MichelFloyd I want to group the articles by topic and then show only the topics that more articles has. The topic will be a word and all the news that are grouped in that topic, contains that word (the topic) in its title. So what I think at first is what you say, a list of words and then show the articles that have that word in the title – Santiago Salem Jul 19 '17 at 19:29
  • Try [this related answer](https://stackoverflow.com/a/38750756/2805154) - it shows how to use mongodb aggregation to count unique words in a text field. Note that you'll want to eliminate "noise" or "stop" words (the, in, an, a, it, etc...) otherwise they'll always rank at the top. – Michel Floyd Jul 19 '17 at 20:24

0 Answers0