关于mongodb的全文检索
2015-02-09 16:08
260 查看
1.在fulltextserach 需要用到切词,切词和语言有关,所以需要设置语言,目前不支持中文,只支持如下的:
http://blog.csdn.net/terry_water/article/details/43671749
2.在使用前,在mongodb需要用命令行设置text索引
设置单个字段索引:
设置多个二级字段全文索引:(同时设置权重)
在这里需要注意的是,一个表只能设置一种语言,如果在一个表中,如果存在多个语言的字段,需要先拆分到几个分表,然后设置text
参考:http://www.oschina.net/translate/mongodb-text-search-tutorial
对于我的需求,需要的设置为:
这种只能对一种语言搜索,因此需要通过脚本,保存到另外一个表:
fulltextsearch_en_catalog_product
fulltextsearch_fr_catalog_product
fulltextsearch_de_catalog_product
fulltextsearch_es_catalog_product
fulltextsearch_it_catalog_product
因此,把_id,name和description保存到对应的表中,对这几个表查询即可。
通过yii2 mongodb模块的方法:
$mongodb = Yii::$app->mongodb;
$data = $mongodb->getCollection("catalog_product")->fullTextSearch("iphone",[],['_id']);
这个方式执行查询产品即可,通过返回的product_id,然后结果其他进行继续查询。
http://blog.csdn.net/terry_water/article/details/43671749
2.在使用前,在mongodb需要用命令行设置text索引
设置单个字段索引:
db.catalog_product.ensureIndex({description: "text"})
设置多个二级字段全文索引:(同时设置权重)
db.catalog_product.ensureIndex({'name.en_name':'text' ,'description.en_description': 'text'}, {weights: {'name.en_name': 10,'description.en_description':5} });设置语言:
db.de.ensureIndex( {txt: "text"}, {default_language: "german"} )
在这里需要注意的是,一个表只能设置一种语言,如果在一个表中,如果存在多个语言的字段,需要先拆分到几个分表,然后设置text
参考:http://www.oschina.net/translate/mongodb-text-search-tutorial
对于我的需求,需要的设置为:
db.catalog_product.ensureIndex({'name.en_name':'text' ,'description.en_description': 'text'}, {weights: {'name.en_name': 10,'description.en_description':5} },{default_language: "german"});
这种只能对一种语言搜索,因此需要通过脚本,保存到另外一个表:
fulltextsearch_en_catalog_product
fulltextsearch_fr_catalog_product
fulltextsearch_de_catalog_product
fulltextsearch_es_catalog_product
fulltextsearch_it_catalog_product
因此,把_id,name和description保存到对应的表中,对这几个表查询即可。
通过yii2 mongodb模块的方法:
$mongodb = Yii::$app->mongodb;
$data = $mongodb->getCollection("catalog_product")->fullTextSearch("iphone",[],['_id']);
这个方式执行查询产品即可,通过返回的product_id,然后结果其他进行继续查询。
相关文章推荐
- 关于sql server全文检索的一些资料收集2
- 关于Notes全文检索
- mongodb 中文全文检索 Coreseek
- mongodb 增加全文检索索引
- 关于Mysql模糊查询的优化-全文检索和Like的使用
- 关于sql server全文检索的一些资料收集1
- 关于Sphinx创建全文检索的索引介绍
- 关于Sphinx创建全文检索的索引介绍
- MongoDB数据自动同步到ElasticSearch(实现中文全文检索)
- 我搜集了很多的开源的关于全文检索的资料,和大家分享
- 关于SQLServer2000的全文检索使用心得
- 关于SQLServer2000的全文检索使用心得
- 找到一篇关于 Oracle 全文检索实践 的文章
- 关于sql全文检索与lucene效率比较的摘要
- 关于Notes全文检索
- 关于SQLServer2000的全文检索使用心得
- MongoDB 全文检索和标签功能
- 关于Asp.net MVC4系统的全文检索功能(1)
- 全文检索引擎Solr系列——整合MySQL、MongoDB
- mongodb如何全文检索