0

I am trying to retrieve some data I stored before from Solr. This is my model.

    @SolrDocument(solrCoreName = "images")
        public class Imagen {
            @Id
            @Field
            private String id;
            @Field
            public String origin_url;
            @Field
            public String[] predominantColor;
            @Field
            public double predominantColor_hue;

If I want to get all the "Imagen" where predominantColor_hue is near of the value I enter, how can I make a customized query for that? Because I just tried to use the

public interface ImagenRepository extends SolrCrudRepository<Imagen, String> {
    Imagen[] findByPredominantColor_hue(double predominantColor_hue);
}

Also tried this

Imagen[] findByPredominantColor_hueIsLessThanAndPredominantColor_hueIsGreaterThan(double predominantColor_hue1, double predominantColor_hue2);

but I get this error:

No property hue found for type String! Traversed path: Imagen.predominantColor.

Maybe if I can make a custom query I can say to Solr that I want the Imagen which have a predominantColor_hue close to the one I want to compare. Maybe +5 and -5. But, how can I make that query? Already googled a lot and nothing found. Thanks and SORRY for my English!

pvpkiran
  • 25,582
  • 8
  • 87
  • 134

1 Answers1

0

Couple of suggestions,

  1. Rename your predominantColor_hue field to predominantColorHue, because _ has a special meaning in spring-data queries.
  2. Your Query should be like this

    List<Imagen> findByPredominantColorHueGreaterThanAndPredominantColorHueLessThan(double predominantColor_hue1, double predominantColor_hue2);
    

If you want to get values near x, Now you can use this method like this

findByPredominantColorHueGreaterThanAndPredominantColorHueLessThan(x-5, x+5)
pvpkiran
  • 25,582
  • 8
  • 87
  • 134