forked from infinilabs/analysis-pinyin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BSP-135: fix search Chinese character with same pinyin issue. (infini…
- Loading branch information
Showing
5 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/org/elasticsearch/index/analysis/ChineseUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.elasticsearch.index.analysis; | ||
|
||
import org.nlpcn.commons.lang.util.StringUtil; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
public class ChineseUtil { | ||
/** | ||
* 汉字始 | ||
*/ | ||
public static char CJK_UNIFIED_IDEOGRAPHS_START = '\u4E00'; | ||
/** | ||
* 汉字止 | ||
*/ | ||
public static char CJK_UNIFIED_IDEOGRAPHS_END = '\u9FA5'; | ||
|
||
public static List<String> segmentChinese(String str){ | ||
if (StringUtil.isBlank(str)) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
List<String> lists = str.length()<=32767?new ArrayList<>(str.length()):new LinkedList<>(); | ||
for (int i=0;i<str.length();i++){ | ||
char c = str.charAt(i); | ||
if(c>=CJK_UNIFIED_IDEOGRAPHS_START&&c<=CJK_UNIFIED_IDEOGRAPHS_END){ | ||
lists.add(String.valueOf(c)); | ||
} | ||
else{ | ||
lists.add(null); | ||
} | ||
|
||
} | ||
return lists; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters