Suvin Nimnaka Sukka
Suvin Nimnaka Sukka

Reputation: 492

Redis OM Spring doesn't return FT.SEARCH results even it exists

I have a data model created with Redis-OM-Spring as follows:

@Data
@Document
public class RedisOAuth2Authorization implements Serializable {

    @Indexed
    @NonNull
    @Id
    private String id;

    @Indexed
    @Searchable
    private String registeredClientId;

    @Indexed
    @Searchable
    private String authorizationCodeValue;
}

I want to search by the authorizationCodeValue and I've defined the following method in my repository.

List<RedisOAuth2Authorization> findByAuthorizationCodeValue(String authorizationCodeValue);

Note that Redis-OM-Spring derives the query by the method name. When I call this method and try to get data (RedisOAuth2Authorization JSON) by the value, it doesn't return any results.

This is the data I have stored in my Redis. Redis Object

This is the query that gets executed when calling the findByAuthorizationCodeValue method (Observed from the profiler):

"FT.SEARCH" "com.my.RedisOAuth2AuthorizationIdx" "@authorizationCodeValue:_YYbHPezqAaWg5uy3QpRQZfqz7_286Ssy6\\-t8mHLMerRDPe8MajCW4DESDS2rZg2epRPaVCshFSmcBLVHygstWsOlQnIRRlWhJZH_eOC3rifsx81r0_Sr62YdKMVuVZx" "LIMIT" "0" "10000"
1) "0"

How can I fix this and get the JSON by authorization code value?

Upvotes: 0

Views: 34

Answers (1)

Guy Royse
Guy Royse

Reputation: 4312

When you tag something as @Searchable in Redis OM Spring, it indexes the field for full-text search in Redis. Full-text search is for human-readable text and not exact matches. It will do stemming, remove stop words, and—most significantly in your case—punctuation.

My guess is that the escaped hyphen in this query is being treated as whitespace in the index and not being found at all.

I would recommend removing the @Searchable as this data is clearly not human-readable text. @Indexed is appropriate.

It is worth noting that the @Searchable and @Indexed annotations in Redis OM Spring are not designed to be used together. I think the last one wins—at least that is the observed behavior.

Upvotes: 1

Related Questions