'search on multiple fields in couchbase spring data where all fields are not passed
I need to write filtering method based on county/status/symbol.
my repository query looks like this
@Query("#{#n1ql.selectEntity} WHERE `platform`='FXSERVICE' " +
"AND `deleted`=false "+
"AND `country` like $country "+
"AND `symbol` like $symbol "+
"AND `state` like $state "+
"AND #{#n1ql.filter}")
Stream<TradeOrderDO> findByCountry(@Param("country") String country, @Param("symbol") String symbol, @Param("state") String state);
and calling the api like this
String country = "INDIA";
String symbol = "INR";
String state = "MANUAL";
tradeOrderRepository.findByCountry(country, symbol, state)
Now I pass all the values (county/symbol/state) it works fine.
But if want to filter with only state and ignore county and symbol
String country = "%%";
String symbol = "%%";
String state = "MANUAL";
tradeOrderRepository.findByCountry(country, symbol, state)
Query does not work. It does not return any value. In query editor of couchbase , '%%' wild card works but not working for repository query. How do I write the query for this type of filtering.
Solution 1:[1]
@Query("#{#n1ql.selectEntity} WHERE `platform`='FXSERVICE' " +
"AND `deleted`=false "+
"AND `country` like '%' || $country || '%' "+
"AND `symbol` like '%' || $symbol || '%' "+
"AND `state` like '%' || $state || '%' "+
"AND #{#n1ql.filter}")
Stream<TradeOrderDO> findByCountry(@Param("country") String country, @Param("symbol") String symbol, @Param("state") String state);
With this query it works.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hiccup |
