Highlight
提示
Highlighting fields can be achieved with the custom annotation @HighLight, which can be added to the fields that need to be highlighted
# @HighLight (opens new window)
-Description: Highlight the note -Usage location: the queried field that needs to be highlighted in the entity class. -Use scenarios as examples: for example, enter the keyword "old man" to query, and expect the part containing "old man" in the content to be displayed in red or bold.
Attribute | Type | You must specify | Default | Description |
---|---|---|---|---|
mappingField | String | No | "" | Highlight the name of the content mapping field. For example, if I want to assign the highlighted content" Old Man "to the field pushCar, I can specify this attribute value as pushCar |
fragmentSize | int | No | 100 | Intercept length of highlighted field, the default is 100 |
numberOfFragments | int | No | -1 | The number of highlighted fragments returned by search, and all are returned by default |
preTag | String | No | < em > | Highlight the tag, and the highlighted content will be behind preTag |
postTag | String | No | < /em > | Highlight the tag, and the highlighted content will come before the postTag |
highlighttype | highlighttypeenum | No | UNIFIED | Highlight type |
requireFieldMatch | boolean | no | true | Whether the highlighted content needs to match the query field. The default value is true. When it is no, non-query fields in the hit content will also be highlighted if they contain highlighted content |
# annotation usage examples
public class Document{
/**
* Fields that need to be highlighted
*/
@HighLight
private String content;
// Omit other irrelevant fields...
}
2
3
4
5
6
7
8
提示
If you don't want the original field value to be overwritten by the highlighted field, then you need to specify the mappingField in the @HighLight annotation and add the field to the corresponding entity class, so that after the configuration, the highlighted content is returned in the highlightedContent field, and the value of the original content field still returns its own value.
For example:
public class Document{
/**
* Fields that need to be highlighted
*/
@HighLight(mappingField = "highlightContent")
private String content;
/**
* The field whose return value is mapped to be highlighted
*/
private String highlightContent;
// Omit other irrelevant fields...
}
2
3
4
5
6
7
8
9
10
11
12
Other
- highlight annotation supports setting the length of the highlighted content interception fragmentSize, the default value is 100
- The highlight annotation supports setting the label of the highlighted content, the default is the label em