redis 如何搜索文本和过滤?

q3aa0525  于 2023-02-03  发布在  Redis
关注(0)|答案(1)|浏览(245)

bounty将在7天后过期。回答此问题可获得+50的声誉奖励。rjdkolb正在寻找此问题的更详细的答案

我正在尝试按索引字段搜索过滤器,并在我的对象中搜索自由文本。看起来它正在搜索公司名称***或搜索项***。如何使其成为SearchStream.freeText的***和***(字符串自由文本)?

  • 我需要使用SearchStream.freeText,因为有许多字段我想搜索。*

我的数据基于以下示例:

companyRepo.deleteAll();
Company redis1 = Company.of("Redis", "wwwabccom", new Point(-122.066540, 37.377690), 526, 2011, Set.of(CompanyMeta.of("Redis", 100, Set.of("RedisTag"))));
Company redis2 = Company.of("Redis", "wwwxyzcom", new Point(-122.066540, 37.377690), 526, 2011, Set.of(CompanyMeta.of("Redis", 100, Set.of("RedisTag"))));

Company microsoft1 = Company.of("Microsoft", "wwwabcnet", new Point(-122.066540, 37.377690), 526, 2011, Set.of(CompanyMeta.of("Redis", 100, Set.of("RedisTag"))));
Company microsoft2 = Company.of("Microsoft", "wwwxyznet", new Point(-122.066540, 37.377690), 526, 2011, Set.of(CompanyMeta.of("Redis", 100, Set.of("RedisTag"))));

companyRepo.save(redis1);
companyRepo.save(redis2);
companyRepo.save(microsoft1);
companyRepo.save(microsoft2);

如果我进行搜索,前两次搜索似乎没问题,但第三次搜索找到的不是***Microsoft***公司的值,而是***Redis***的值

var result1 = entityStream.of(Company.class)
        .filter(Company$.NAME.eq("Redis"))
        .filter("*abc*")
        .collect(Collectors.toList());
System.out.println("Search1:");
result1.forEach(System.out::println);

var result2 = entityStream.of(Company.class)
        .filter(Company$.NAME.eq("Microsoft"))
        .filter("*xyz*")
        .collect(Collectors.toList());
System.out.println("Search2:");
result2.forEach(System.out::println);

var result3 = entityStream.of(Company.class)
      .filter(Company$.NAME.eq("Microsoft"))
      .filter("*co*")
      .collect(Collectors.toList());
System.out.println("Search3:");
result3.forEach(System.out::println);

程序的输出:

搜索1:

公司(ID=01GR46XB7BMJXV5WK3AJ3FA4M9,名称=Redis,标签=[],网址=wwwabccom,公司(ID=01GR46XB974C3JJDAW70N20SFV,名称=微软,标签=[],网址=wwwabcnet,

搜索2:

公司(ID=01GR46XB9388CRW0P71QM45K43,名称=Redis,标签=[],网址=wwwxyzcom,公司(ID=01GR46XB9ABBV3TN9BTQFP08C1,名称=微软,标签=[],网址=wwwxyznet,

搜索3:

公司(ID=01GR46XB7BMJXV5WK3AJ3FA4M9,名称=Redis,标签=[],网址=wwwabccom,公司(ID=01GR46XB9388CRW0P71QM45K43,名称=Redis,标签=[],网址=wwwxyzcom,
我从Ruby开始

docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:6.2.6-v2

模块表

127.0.0.1:6379> module list
1) 1) "name"
   2) "timeseries"
   3) "ver"
   4) (integer) 10805
2) 1) "name"
   2) "graph"
   3) "ver"
   4) (integer) 21005
3) 1) "name"
   2) "ReJSON"
   3) "ver"
   4) (integer) 20403
4) 1) "name"
   2) "search"
   3) "ver"
   4) (integer) 20604
5) 1) "name"
   2) "bf"
   3) "ver"
   4) (integer) 20403

梅文

<dependency>
  <groupId>com.redis.om</groupId>
  <artifactId>redis-om-spring</artifactId>
  <version>0.6.4</version>
</dependency>
qoefvg9y

qoefvg9y1#

你能从CLI发布modules list的输出吗?我怀疑这与Redis的标记化/转义https://redis.io/docs/stack/search/reference/escaping/的规则有关,前缀https://redis.io/docs/stack/search/reference/query_syntax/#prefix-matching和中缀/后缀匹配https://redis.io/docs/stack/search/reference/query_syntax/#infixsuffix-matching

相关问题