有没有办法使用EntityStream API搜索redis-om-spring的所有字段?

nhaq1z21  于 2023-01-25  发布在  Redis
关注(0)|答案(1)|浏览(124)

redis-om-spring中,我只需向存储库添加一个搜索方法就可以搜索所有字段。

public interface ProductRepository extends RedisDocumentRepository<Product, String> {
    Page<Product> search(String text, Pageable pageable);
}

使用EntityStream时,我可以搜索特定字段,但不能搜索所有字段。

var result = entityStream.of(Product.class)
   .anyMatch(new StartsWithPredicate<>(Product$.UNIQUE_ID.getField(),"100790"))

@AllArgsConstructor
public class Product{
   @Id
   String uniqueId;
   @Searchable
   String field1;
   @Searchable   
   String field2;
   @Searchable
   String fieldN;
}

repo.save(new Product("UA","searchForA1","searchForA2","searchForAN");
repo.save(new Product("UB","searchForB1","searchForB2","searchForBN");
repo.save(new Product("UC","searchForC1","searchForC2","searchForCN");

我需要在所有字段中搜索。我在EntityStream API中遗漏了什么还是这是不可能的?
产生的东西:

FT.SEARCH my-idx "thesearchTerm"
4xy9mtcn

4xy9mtcn1#

是的,SearchStream接口中有一个filter方法,它接受自由格式的文本String:

SearchStream<E> filter(String freeText);

请参见www.example.comhttps://github.com/redis/redis-om-spring/blob/main/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/SearchStream.java#L20

相关问题