Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Fetching String of specified length in solr

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 334
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: