mongodb - Symfony 3.4 中 mongodb 中的全文搜索
问题描述
我正在尝试在 mongodb 中使用全文搜索:
db.Product.createIndex({"name": "text"})
db.Product.find({$text: {$search: "xxxxx"}})
如何在控制器中使用它来 symfony?
解决方案
首先创建产品实体(根据您的需要调整)
<?php
/**
* @Document
* @Index(keys={"name"="text"})
*/
class Product
{
/** @Id */
public $id;
/** @Field(type="string") */
public $name;
/** @Field(type="float") */
public $price;
}
查看$name
和@Index
注释
然后使用查询构建器 text() 方法
// Run a text search against the index
$qb = $dm->createQueryBuilder('Product')
->text('words you are looking for');
您可以在这里找到更多信息
另一种方法是使用来自学说查询构建器的 expr() 创建本机查询
推荐阅读
- macos - 打印信封时如何在 MS Word 中本地化寄信人地址的格式?
- typescript - 从 TypeScript 生成 GraphQL 模式?
- javascript - 当数据少于 3 个值时,未出现 AMCharts 系列的问题
- javascript - 未捕获的 TypeError:FormData 构造函数:参数 1 未实现接口 HTMLFormElement
- sql - 在 PostgreSQL 的窗口函数中按降序聚合排序
- excel - SAS 导出数据集以替换 2016 Excel 文件中的单个工作表
- java - 使用带有自定义类型 Feature 参数的方法
- html - 是否可以在 HTML/CSS 中创建这种移动与桌面布局?
- java - 如何将内置的休眠添加到本地 Maven 仓库?
- python - 将 CSV 文件内容与 filecmp 进行比较并忽略元数据