文档库--搜索全部(内容前后100字符)
This commit is contained in:
+30
@@ -455,6 +455,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
boolean flag = judgeContains(s, selectValueTwo);
|
||||
if(flag){
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
s = getFileText(s, selectValue);
|
||||
String chStr = String.valueOf(s.charAt(i));
|
||||
if (selectValue.contains(String.valueOf(chStr))) {
|
||||
chStr = "<text class='highlight-class'>" + chStr + "</text>";
|
||||
@@ -486,9 +487,12 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
if("file_text".equals(key)){
|
||||
for (List<String> valueList : (List<List<String>>) entry.getValue()) {
|
||||
for (String s : valueList) {
|
||||
s = s.replace("\n","");
|
||||
int count = 0;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (StringUtils.isNotBlank(s)) {
|
||||
//判断file_text中是否有搜索内容,如果有
|
||||
s = getFileText(s, selectValue);
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
String chStr = String.valueOf(s.charAt(i));
|
||||
if (selectValue.contains(String.valueOf(chStr))) {
|
||||
@@ -538,6 +542,32 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
|
||||
}
|
||||
|
||||
private String getFileText(String fileTextInfo,String selectValue){
|
||||
String beginStr = "";
|
||||
String endStr = "";
|
||||
for (int i = 0; i < fileTextInfo.length(); i++) {
|
||||
String chStr = String.valueOf(fileTextInfo.charAt(i));
|
||||
if(selectValue.contains(chStr)){
|
||||
if(i >=100){
|
||||
int begin = i - 100;
|
||||
beginStr = fileTextInfo.substring(begin, i);
|
||||
int b=0;
|
||||
}else{
|
||||
beginStr = fileTextInfo.substring(0, i);
|
||||
}
|
||||
int index = fileTextInfo.length() - i;
|
||||
if(index<=100){
|
||||
endStr = fileTextInfo.substring(i,fileTextInfo.length());
|
||||
}else{
|
||||
endStr = fileTextInfo.substring(i,i+100);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
String result = beginStr + endStr;
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean judgeContains(String oldStr, String newStr) {
|
||||
if (StringUtils.isBlank(oldStr) || StringUtils.isBlank(newStr)) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user