Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1791

Full text searching a Turkish word using mongodb-java-driver does not work

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            ozlerhakan Hakan Özler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: