redis / redis-om-spring

Spring Data Redis extensions for better search, documents models, and more
MIT License
607 stars 94 forks source link

Add checking the array has a specific number on NumericField class #400

Open chiyongs opened 7 months ago

chiyongs commented 7 months ago

Hi there,

https://redis.io/docs/interact/search-and-query/indexing/#index-json-arrays-as-numeric According to the guide page, I can index the JSON array to NUMERIC. With this feature, I can also check if the number in the array is in a specific range and if the array has a specific value. However, the com.redis.om.spring.metamodel.index.NumericField class does not provide a way to verify that an array contains a specific number. Since the above features are not supported, I need to put a string other than a number into an array to see if it is included using a TAG index, or use a native query using the RedisDocumentRepository. However, I would like to implement these features using EntityStream and NumericField.

For instance, implement it like the code below or there seems to be a way to change it like TagField's in method.

public InPredicate<E, ?> containsLong(Long... values) {
    return new InPredicate<>(searchFieldAccessor, Arrays.asList(values));
}

I would like to ask for your opinion on this.

bsbodden commented 7 months ago

@chiyongs can you help me a concrete example using EntityStreams of what you think this might look like, that way I can start tinkering with the cleanest way to accomplish it. Cheers!