Reputation: 501
In my application I want to permit to the user to search for ads with some words. So I want to get all ads that contain all the word in the list. For example if he search for : Honda civic 2017 , I want to get all ads that have this words without order , he can get ads with 2001 civic honda , honda 2001 civic . so far I tried with Spring data Repository : interface :
Page<Annonce> findByTitreContaining(String titres ,Pageable page);
Controller :
String title;
annonces=annoncedao.findByTitreIn(title, page);
But this one give me only the ads who contain the String
Upvotes: 0
Views: 302
Reputation: 12744
A contains search is that your query parameter is wrapped with a %
. In your case you search for %Honda civic 2017%
. Means that everything before and after your query string could be anything but have to match Honda civic 2017
exactly anywhere.
Your use case is more a full text search. Mostly done with NoSql
Databases. Spring provides some of them out of the box. For example Apache Solr
or Elasticsearch
.
A workaround for your use case could be that you split your query String and make an own contains search for every splitted String. Afterwards set the results back into your return object. But as I said this is more a workaround.
I have not used the hibernate search, yet. So dont know if its suitable but maybe it helps. Add full-text search to your application with Hibernate Search
Upvotes: 1