Is there a way to search all fields with redis-om-spring using the EntityStream API?

634 views Asked by At

In redis-om-spring I can search all fields by simply adding a search method to the repository.

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

When using the EntityStream, I can search on specific fields, but not across all fields.

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");

I need to search across all fields. Am I missing something in the EntityStream API or is this not possible?

Something that generates:

FT.SEARCH my-idx "thesearchTerm"
1

There are 1 answers

2
BSB On BEST ANSWER

Yes, there is a filter method in the SearchStream interface that takes a free-form text String:

SearchStream<E> filter(String freeText);

See https://github.com/redis/redis-om-spring/blob/main/redis-om-spring/src/main/java/com/redis/om/spring/search/stream/SearchStream.java#L20