示例#1
0
 def search_source_word(self, word):
     try:
         collections = get_db()[DB_SCHEMA_NAME]
         docs = collections.find({'name': word})
         for doc in docs:
             return normalize_bson_to_json(doc)
         return None
     except Exception as e:
         log_exception("db connection exception ", AppContext.getContext(),
                       e)
         return None
示例#2
0
 def search_target(self, word, locale):
     try:
         collections = get_db()[DB_SCHEMA_NAME]
         docs = collections.find({
             'parallel_words': {
                 '$elemMatch': {
                     'locale': locale,
                     'name': word
                 }
             }
         })
         for doc in docs:
             return normalize_bson_to_json(doc)
         return None
     except Exception as e:
         log_exception("db connection exception ", AppContext.getContext(),
                       e)
         return None
示例#3
0
    def search_word(self, src_word, src_locale, tgt_locale):
        try:
            collections = get_db()[DB_SCHEMA_NAME]
            docs = collections.find({
                '$or': [{
                    '$and': [{
                        'name': src_word,
                        'locale': src_locale
                    }, {
                        'parallel_words': {
                            '$elemMatch': {
                                'locale': tgt_locale
                            }
                        }
                    }]
                }, {
                    '$and': [{
                        'locale': tgt_locale
                    }, {
                        'parallel_words': {
                            '$elemMatch': {
                                'locale': src_locale,
                                'name': src_word
                            }
                        }
                    }]
                }]
            })

            for doc in docs:
                return normalize_bson_to_json(doc)
            return None
        except Exception as e:
            log_exception("db connection exception ", AppContext.getContext(),
                          e)
            return None