0

I am trying to search & char in mongo, but looks like it is ignored.

Here is the queryplan

    mongos> db.mycoll.explain().find({"$text" : { "$search" : "&" } }) 
 {
                                        "shardName" : "shard-b",
                                        "connectionString" : "shard-b/sam-pc:30100,sam-pc:30101",
                                        "serverInfo" : {
                                                "host" : "sam-pc",
                                                "port" : 30101,
                                                "version" : "3.4.7",
                                                "gitVersion" : "cf38c1b8a0a8dca4a11737581beafef4fe120bcd"
                                        },
                                        "plannerVersion" : 1,
                                        "namespace" : "test.mycoll",
                                        "indexFilterSet" : false,
                                        "parsedQuery" : {
                                                "$text" : {
                                                        "$search" : "&",
                                                        "$language" : "english",
                                                        "$caseSensitive" : false,
                                                        "$diacriticSensitive" : false
                                                }
                                        },
                                        "winningPlan" : {
                                                "stage" : "SHARDING_FILTER",
                                                "inputStage" : {
                                                        "stage" : "TEXT",
                                                        "indexPrefix" : {

                                                        },
                                                        "indexName" : "custom_text_index",
                                                        "parsedTextQuery" : {
                                                                "terms" : [ ],
                                                                "negatedTerms" : [ ],
                                                                "phrases" : [ ],
                                                                "negatedPhrases" : [ ]
                                                        },
                                                        "textIndexVersion" : 3,
                                                        "inputStage" : {
                                                                "stage" : "TEXT_MATCH",
                                                                "inputStage" : {
                                                                        "stage" : "TEXT_OR"
                                                                }
                                                        }
                                                }
                                        },
                                        "rejectedPlans" : [ ]
                                }
                        ]
                }

I could not find documentations regarding ignored chars/punctuation in mongo text index.

MongoDB server version: 3.4.7 Language is English.

Can someone point me to the right direction?

Sameer
  • 3,124
  • 5
  • 30
  • 57
  • Text search is intended for searching words rather than strings, so punctuation symbols like `&` will be ignored. You can see what `$search` terms are found via the `parsedTextQuery` section of your explain output. – Stennie Jan 13 '19 at 00:03
  • @Stennie: Is there no way to control this behavior: to not discard punctuation chars? Elastic search does not do this by default. – Sameer Jan 13 '19 at 03:12
  • This text search behaviour is currently not configurable (as at MongoDB 4.0). All available [options for text indexes](https://docs.mongodb.com/manual/core/index-text/) are covered in the MongoDB documentation. If you need to frequently search for symbols and punctuation you could consider the [Model Data to Support Keyword Search](https://docs.mongodb.com/manual/tutorial/model-data-for-keyword-search/) approach. Regexes are also an option, but are not recommendable giving [limited index use](https://docs.mongodb.com/manual/reference/operator/query/regex/#index-use). – Stennie Jan 13 '19 at 06:51

0 Answers0