我試圖在跨多個字段的搜索字符串中查找所有單詞。例如: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