Details
-
Task
-
Resolution: Done
-
Major - P3
-
None
-
3.0.0
-
None
-
None
-
My System settings:
Windows 7 64-bit
6GB RAM DDR3, Intel Core i7 1.73GHz
MongoDB version 3.0
Mongo Java Driver version: mongo-java-driver:3.0.0
Description
I have an index on the text field with its default language which is Turkish. When I query in the mongo shell I get the total number which is 17 using the following script:
> use newspaper
|
> db.news.getIndices()
|
[
|
{
|
"v" : 1,
|
"key" : {
|
"_id" : 1
|
},
|
"name" : "_id_",
|
"ns" : "newspaper.news"
|
},
|
{
|
"v" : 1,
|
"key" : {
|
"_fts" : "text",
|
"_ftsx" : 1
|
},
|
"name" : "text_text",
|
"ns" : "newspaper.news",
|
"default_language" : "turkish",
|
"weights" : {
|
"text" : 1
|
},
|
"language_override" : "language",
|
"textIndexVersion" : 2
|
}
|
]
|
> db.news.find({$text:{$search: "maç"}}).count()
|
17
|
When attempting to use the same query int the same db in Java using MongoDB Java Driver, I get 0 result. Here is the code snippet that I use:
final MongoClient mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost")); |
final MongoDatabase newspaper = mongoClient.getDatabase("newspaper"); |
final MongoCollection<Document> news= newspaper.getCollection("news"); |
Document textSearch = new Document("$text", new Document("$search", "maç")); |
long count = news.count(textSearch); |
System.out.println(count);
|
I found that this only happens because of the special turkish characters when they are included in a word, here are the turkish characters that we use day in and day out: " ı, ç, ü, ö, ş, ğ ". But when I type a word that does not contain any of them, let's say, "hafta" (eng: "week") I get the same result in both mongo shell and java.