我试图在跨多个字段的搜索字符串中查找所有单词。例如:MongoDB - 在多个字段中查找所有搜索字符串单词
如果我在这个数据来搜索“的Java咖啡”:
{ _id: 1, name: "Java Hut", description: "Coffee and cakes" },
{ _id: 2, name: "Burger Buns", description: "Gourmet hamburgers" },
{ _id: 3, name: "Coffee Shop", description: "Just coffee" },
{ _id: 4, name: "Clothes Clothes Clothes", description: "Discount clothing" },
{ _id: 5, name: "Java Shopping", description: "Indonesian goods Hut" },
{ _id: 6, name: "Java Coffee", description: "goods Hut" },
{ _id: 7, name: "Coffee Shop", description: "Just coffee Java" }
我想它在每个领域单独搜索每个字,并返回了各自的所有文件在任何指定的字段中搜索单词。
我应该得到的ID 1,6和7追溯到因为这些比赛的结果:
{ _id: 1, name: "**Java** Hut", description: "**Coffee** and cakes" },<br>
{ _id: 2, name: "Burger Buns", description: "Gourmet hamburgers" },<br>
{ _id: 3, name: "Coffee Shop", description: "Just coffee" },<br>
{ _id: 4, name: "Clothes Clothes Clothes", description: "Discount clothing" },<br>
{ _id: 5, name: "Java Shopping", description: "Indonesian goods Hut" },<br>
{ _id: 6, name: "**Java Coffee**", description: "goods Hut" },<br>
{ _id: 7, name: "Coffee Shop", description: "Just **coffee Java**" }
我如何能以高效的方式为蒙戈来执行它实现这一目标的任何想法?
谢谢,这对我有效。如果其中一个单词是部分的,它甚至可以工作,如'jav'而不是'java'。你知道是否有办法让它适用于多个部分词汇? – Kendall
我不希望部分单词在文本搜索中可靠地工作,因为它使用单词词干而不是部分匹配。 – JohnnyHK