接下来处理精确查询的功能部分。
如果使用上一章节的模糊查询来搜索John Smith,可以发现包含Smith的两个作者都会匹配到。这里既然是做精确查询,是假定只有John Smith会被匹配,而不会命中Jane Smith,这就要用到Term Query。
下面的开始日期和结束日期、点赞数范围分别是对日期类型和整数类型的范围搜索,这里可以用Range Query。
最后,当同时输入多个条件时,还需要用Bool查询把多个条件组合在一起。
因为条件比较多,首先编写一个Java Bean用来传递参数。
public class SearchForm {
private int type;
private String keyword;
private String author;
private String startDate;
private String endDate;
private String minLikes;
private String maxLikes;
用type=0表示使用了模糊查询,type=1表示使用了精确查询。controller代码修改如下:
@RequestMapping("/blogs")
public String query(Model model, SearchForm searchForm, Inte