For fetching a string for a specific value and length, here are 2 ways to do that. First using @Query and another using solr Criteria.
In the below code it first searches for the string match and then suing filters we have defined the length of that string
@Query(value = "sentence:*?0*",filters="sentence:/.{0,149}./")
Page<Sentence> findBySentence(String str, Pageable pageable);
Using criteria we need to use expression to search for specified length. For sentence match we can either use contains or expression.
new Criteria();
Criteria conditions = ((Criteria.where("sentence").expression("*"+str+"*")).and(Criteria.where("sentence").expression("/.{0,149}./"))); // using expression for stirng search
//Criteria conditions = ((Criteria.where("sentence").contains(str)).and(Criteria.where("sentence").expression("/.{0,149}./"))); // using contains for stirng search
SimpleQuery search = new SimpleQuery(conditions);
sentenceList = solrTemplate.queryForPage(search, Subtitle.class);
0 Comment(s)