Database Reference
In-Depth Information
Listing 12-42. Search for Products
@Action(value = "/productsearch/{q}",results = {@Result(name = "success", type = "json")})
public String productSearch() {
try {
graphStory.setMappedProductSearch(graphStoryDAO
.getProductDAO().search(q));
}
catch (Exception e) {
log.error(e);
}
return SUCCESS;
}
// search method in ProductDAO
public MappedProductSearch[] search(String q) {
q = q.trim().toLowerCase() + ".*";
try {
ResultSet rs = cypher.resultSetQuery(
"MATCH (p:Product) " +
" WHERE lower(p.title) =~ {1} " +
" RETURN count(*) as name, TOSTRING(ID(p)) as id, " +
" p.title as label " +
" ORDER BY p.title LIMIT 5",
map("1", q));
ResultSetMapper<MappedProductSearch> resultSetMapper =
new ResultSetMapper<MappedProductSearch>();
List<MappedProductSearch> mappedProductSearchResults =
resultSetMapper.mapResultSetToListMappedClass(rs, MappedProductSearch.class);
MappedProductSearch[] mappedProductSearch = new
MappedProductSearch[mappedProductSearchResults.size()];
return mappedProductSearchResults.toArray(mappedProductSearch);
}
catch (Exception e) {
log.error(e);
return null;
}
}
Search WWH ::




Custom Search