Match
# Token matching related function API
match(boolean condition, R column, Object val);
notMatch(boolean condition, R column, Object val, Float boost);
// The following APIs are only supported in version 0.9.12+, if necessary, you can upgrade the EE version by yourself
matchPhase(boolean condition, R column, Object val, Float boost);
matchAllQuery();
matchPhrasePrefixQuery(boolean condition, R column, Object val, int maxExpansions, Float boost);
multiMatchQuery(boolean condition, Object val, Operator operator, int minimumShouldMatch, Float boost, R... columns);
queryStringQuery(boolean condition, String queryString, Float boost);
prefixQuery(boolean condition, R column, String prefix, Float boost);
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
Note
Note: The field index type that needs to be matched by word segmentation must be text, and a tokenizer must be specified for it. The required tokenizer must be installed in advance, otherwise the default tokenizer of es will be used, which is not well supported for Chinese.
- Participle matching
- Example: match("content", "Lao Wang")--->content contains the keyword 'Lao Wang' If the granularity of the word segmentation is set relatively fine, Lao Wang may be split into "Lao" and "Wang", As long as the content contains "old" or "king", it can be searched out. For other APIs, please refer to the following code examples.
# code example
@Test
public void testMatch(){
// The input will be segmented, as long as one word in all segmented words matches the content, the data will be queried, ignoring the sequence of word segmentation
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
wrapper.match(Document::getContent,"Technology");
List<Document> documents = documentMapper.selectList(wrapper);
System.out.println(documents.size());
}
@Test
public void testMatchPhase() {
// The input will be segmented, but all the segmented words need to be included in the result, and the order is the same, otherwise the result cannot be queried
// For example, the data in es is technically strong, if the search keyword is technically strong, the result cannot be queried
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
wrapper.matchPhase(Document::getContent, "Technology");
List<Document> documents = documentMapper.selectList(wrapper);
System.out.println(documents);
}
@Test
public void testMatchAllQuery() {
// Query all data, similar to mysql select all.
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
wrapper.matchAllQuery();
List<Document> documents = documentMapper.selectList(wrapper);
System.out.println(documents);
}
@Test
public void testMatchPhrasePrefixQuery() {
// Prefix matching query Only the last word of the query string can be used as a prefix
// The prefix may match thousands of words, which not only consumes a lot of system resources, but also the result is not very useful, so you can provide the input parameter maxExpansions, if not written, the default is 50
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
wrapper.matchPhrasePrefixQuery(Document::getCustomField, "Ulabala", 10);
List<Document> documents = documentMapper.selectList(wrapper);
System.out.println(documents);
}
@Test
public void testMultiMatchQuery() {
// Query data containing Pharaoh from multiple specified fields
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
wrapper.multiMatchQuery("Pharaoh", Document::getTitle, Document::getContent, Document::getCreator, Document::getCustomField);
// Among them, the default operator is OR, and the default minShouldMatch is 60%. These two parameters can be adjusted as needed, and our api is supported. For example:
// where AND means that all searched Tokens must be matched, OR means that only one Token matches. minShouldMatch 80 means only query data with a matching degree greater than 80%
// wrapper.multiMatchQuery("Pharaoh",Operator.AND,80,Document::getCustomField,Document::getContent);
List<Document> documents = documentMapper.selectList(wrapper);
System.out.println(documents.size());
System.out.println(documents);
}
@Test
public void queryStringQuery() {
// Query data containing the keyword old man from all fields
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
wrapper.queryStringQuery("Old man");
List<Document> documents = documentMapper.selectList(wrapper);
System.out.println(documents);
}
@Test
public void prefixQuery() {
// Query all data whose creator starts with "next door", such as the old man next door and the old man next door, can be found
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
wrapper.prefixQuery(Document::getCreator, "Next door");
List<Document> documents = documentMapper.selectList(wrapper);
System.out.println(documents);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Help us improve this document (opens new window)
Last update: 2024/03/29