Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-3710

How does MongoDB text queries score documents?

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Won't Fix
    • Icon: Blocker - P1 Blocker - P1
    • 01112017-cleanup
    • mongodb-2.6
    • manual
    • None

    Description

      I created an text index this way:

      db.myCollection.ensureIndex(

      {firstName:"text", lastName:"text", email:"text", birthDate:"text"}

      ,{name:"text_index", weights:{lastName:2, email:2}})

      so that I can set a threshold (maybe 3) as a minimum score to consider that 2 records are "almost the same".

      Now I create example/dummy documents, for instance:

      {firstName:"ROBERT", lastName:"LANE", email: "imnotxavier@mail.com"}

      and perform this query db.myCollection.find({$text:{$search: "ROBERT LANE"}},{score:{$meta:"textScore"}})

      I get this:

      { "_id" : ObjectId("53b6c9f12a48e559dec0f6ab"), "firstName" : "ROBERT", "lastName" : "LANE", "email" : "imnotxavier@mail.com", "score" : 3.3000000000000003 }

      Why does MongoDB do this instead of returning a document with score==3?

      I need to know a little more about the details of the scoring system in order to correctly set a threshold and make better decisions.

      Attachments

        Activity

          People

            Unassigned Unassigned
            antonimmo Antonio Quintana
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              9 years, 32 weeks ago