Indexing strategies for text search

I have a database with job postings. I am implementing text search on this database for a web app, and am looking for guidance on the best strategy to build an index. There are three specific fields that should be searched: Title, Company, and Description.

I built a compound index with the weights of:

  • Title: 10
  • Company: 5
  • Description: 2

Search results are not coming back as expected, though. For example, if I search “data entry” my expectation would be that items with “data entry” in the title would be prioritized given the weight I put on the field. That’s not happening, though. Any suggestions on how to either optimize this index, or if I should be taking a completely different approach to indexing?

Hi @Eric_Kenney1,

Sounds like you are doing things correctly. This is exactly how it’s supposed to work.

Did you try to print score to see what results you are getting exactly and why the top result gets a better score than the one with “data entry” in the title?

db.articles.find(
   { $text: { $search: "data entry" } },
   { score: { $meta: "textScore" } }
)

If you want to prioritize the title more, you could try to adjust the weights a bit so something found in the title would come out first.

Cheers,
Maxime.