Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-28522

Is there a way to force at least one term from a list in a full text search in MongoDB?

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Text Search
    • None

      Sorry if this is the wrong place to put this issue but I wrote in both: stackoverflow with mongodb tag and google groups but no one replied. This is really important for me, please help me. Maybe this is just a question, maybe a feature request depending of your answer:

      Is there a way to force at least one term from a list in a full text search in MongoDB?

      Let me show you a very simple example:

      db.palette.insertMany([
          {colors: "green,black"}, 
          {colors: "green,red"}, 
          {colors: "green,blue"}
      ])
      

      Then I created a text index:

      db.palette.createIndex({colors: "text"})
      

      Note that MongoDB firstly splits the string values by the comma internally in order to index words, I even checked that using db.palette.validate() information.

      Finally I tried to search with the following command using a query string similar to the some official example from documentation:

      db.palette.find({$text: {$search: "\"green\" red blue"}})
      

      I need to retrieve only second and third document but the result includes the first one too (green,black). I am asking for a way to do exactly what MySQL does in this case if I use a query like this:

      "+green +(red blue)"
      

      MySQL selects all the rows that contain "green" AND ("red" OR "blue") in some of the indexed columns. Note that if some row only contains green it won't be selected.

      Thanks in advanced

            Assignee:
            Unassigned Unassigned
            Reporter:
            kindox Kindox
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: