I have a spring MVC application with search capabilities.
Flow: UI > CONTROLLER > BL > DATA > SOLR
Users are allowed to search something using multiple fields, example search by name or department. The business layer needs to have a Lucene Query Builder which accepts the string and builds a proper Lucene query for SOLR.
My Controller:
@GetMapping(params = "name")
public Page<User> findUserByName(@RequestParam("name") final String name) {
return userService.findUserByName(name);
}
@GetMapping(params = "department")
public Page<User> findUserByDepartment(@RequestParam final String department) {
return userService.findUserByFulltext(department);
}
Dummy Query Builder
public String searchByNameQuery(final String name) {
return "nm:" + name;
}
public String searchByDepartmentQuery(final String department) {
return "dpt:" + department;
}
Now this dummy query builder doesn't support wildcard or any other varieties. I am going through the Apache Lucene Query API (added lucene core-7.7.1 to project as well) and bunch of articles that teaches how to use different types of Query implementations (TermQuery, PhraseQuery, BooleanQuery, etc) but it doesn't make sense at all. In the end, I am still manually building the queries.
Can someone please help by showing how can I have a proper Lucene Query Builder Class?
I need to generate queries for these type of texts with exact phrase and wildcards
(exact)Search by name: Ohio State University
Search by name: *State
Search by name: Ohio*University
Search by name: Ohio State*
Search by Department:Computer Science Dept
Search by Department: *Science
Combined Query:
nm:"Ohio State University" AND dpt:"Computer Science"