如教程前面所述,Redis Stack 中搜索和查询的目标之一是提供丰富的查询功能,例如
开始使用 Redis Stack 查询功能的最佳方法是查看各种条件选项。
> FT.SEARCH "idx:movie" "heat" RETURN 2 title plot
1) (integer) 4
2) "movie:1141"
3) 1) "title"
2) "Heat"
3) "plot"
4) "A group of professional bank robbers start to feel the heat from police when they unknowingly leave a clue at their latest heist."
4) "movie:818"
5) 1) "title"
2) "California Heat"
3) "plot"
4) "A lifeguard bets he can be true to just one woman."
6) "movie:736"
7) 1) "title"
2) "Chicago Justice"
3) "plot"
4) "The State's Attorney's dedicated team of prosecutors and investigators navigates heated city politics and controversy head-on,while fearlessly pursuing justice."
8) "movie:1109"
9) 1) "title"
2) "Love & Hip Hop: Miami"
3) "plot"
4) "'Love and Hip Hop Miami' turns up the heat and doesn't hold back in making the 305 the place to be. Multi-platinum selling hip-hop legend Trick Daddy is back in the studio collaborating ..."
第一行包含与查询条件匹配的文档数量 (4
),然后是电影列表。
此查询是“无字段”条件,这意味着查询引擎已
title
和 plot
)heat
和相关单词,这就是为什么返回电影:736 的原因,因为它在剧情中包含单词 heated
(词干提取)在这种情况下,您必须使用 @title
符号将标准设置为 title 字段。
> FT.SEARCH "idx:movie" "@title:heat" RETURN 2 title plot
1) (integer) 2
2) "movie:1141"
3) 1) "title"
2) "Heat"
3) "plot"
4) "A group of professional bank robbers start to feel the heat from police when they unknowingly leave a clue at their latest heist."
4) "movie:818"
5) 1) "title"
2) "California Heat"
3) "plot"
4) "A lifeguard bets he can be true to just one woman."
因此只返回 2 部电影。
为此,您需要在字段条件周围添加括号并添加 -
符号到“california”。
> FT.SEARCH "idx:movie" "@title:(heat -california)" RETURN 2 title plot
1) (integer) 1
2) "movie:1141"
3) 1) "title"
2) "Heat"
3) "plot"
4) "A group of professional bank robbers start to feel the heat from police when they unknowingly leave a clue at their latest heist."
只有一部电影被返回。
如果您不添加 ( .. )
,则 -california
条件将应用于所有文本字段。
您可以使用以下查询进行测试
> FT.SEARCH "idx:movie" "@title:(heat -woman)" RETURN 2 title plot
> FT.SEARCH "idx:movie" "@title:heat -woman" RETURN 2 title plot
如您所见,第一个查询只在标题中搜索 woman,并返回两部电影“Heat”和“California Heat”,而第二个查询从列表中删除了“California Heat”,因为剧情包含单词 woman
.