Lucene5学习之拼音搜索

简介:

     今天来说说拼音检索,这个功能其实还是用来提升用户体验的,别的不说,最起码避免了用户切换输入法,如果能支持中文汉语拼音简拼,那用户搜索时输入的字符更简便了,用户输入次数少了就是为了给用户使用时带来便利。来看看一些拼音搜索的经典案例:


 

 

 

      看了上面几张图的功能演示,我想大家也应该知道了拼音检索的作用以及为什么要使用拼音检索了。那接下来就来说说如何实现:

     首先我们我们需要把分词器分出来的中文词语转换为汉语拼音,Java中汉字转拼音可以使用pinyin4j这个类库,当然icu4j也可以,但icu4j不支持多音字且类库jar包体积有10M多,所以我选择了pinyin4j,但pinyin4j支持多音字并不是说它能根据词语自动判断汉字读音,比如:重庆,pinyin4j会返回chongqing zhongqing,最终还是需要用户去人工选择正确的拼音的。pinyin4j也支持简拼的,所以拼音转换这方面没什么问题了。

    接下来要做的就是要把转换得到的拼音进行NGram处理,比如:王杰的汉语拼音是wangjie,如果要用户完整正确的输入wangjie才能搜到有关“王杰”的结果,那未免有点在考用户的汉语拼音基础知识,万一用户前鼻音和后鼻音不分怎么办,所以我们需要考虑前缀查询或模糊匹配,即用户只需要输入wan就能匹配到"王"字,这样做的目的其实还是为了减少用户操作步骤,用最少的操作步骤达到同样的目的,那必然是最讨人喜欢的。再比如“孙燕姿”汉语拼音是“sunyanzi”,如果我期望输入“yanz”也能搜到呢?这时候NGram就起作用啦,我们可以对“sunyanzi”进行NGram处理,假如NGram按2-4个长度进行切分,那得到的结果就是:su un ny

 ya an nz zi sun uny nya yan anz nzi suny unya nyan yanz anzi,这样用户输入yanz就能搜到了。但NGram只适合用户输入的搜索关键字比较短的情况下,因为如果用户输入的搜索关键字全是汉字且长度为20-30个,再转换为拼音,个数又要翻个5-6倍,再进行NGram又差不多翻了个10倍甚至更多,因为我们都知道BooleanQuery最多只能链接1024个Query,所以你懂的。 分出来的Gram段会通过CharTermAttribute记录在原始Term的相同位置,跟同义词实现原理差不多。所以拼音搜索至关重要的是分词,即在分词阶段就把拼音进行NGram处理然后当作同义词存入CharTermAttribute中(这无疑也会增加索引体积,索引体积增大除了会额外多占点硬盘空间外,还会对索引重建性能以及搜索性能有所影响),搜索阶段跟普通查询没什么区别。如果你不想因为NGram后Term数量太多影响搜索性能,你可以试试EdgeNGramTokenFilter进行前缀NGram,即NGram时永远从第一个字符开始切分,比如sunyanzi,按2-8个长度进行EdgeNGramTokenFilter处理后结果就是:su   sun   suny   sunya   sunyan  sunyanz   sunyanzi。这样处理可以减少Term数量,但弊端就是你输入yanzi就没法搜索到了(匹配粒度变粗了,没有NGram匹配粒度精确),你懂的。

     下面给出一个拼音搜索的示例程序,代码如下:

Java代码   收藏代码
  1. package com.yida.framework.lucene5.pinyin;  
  2.   
  3. import java.io.IOException;  
  4.   
  5. import net.sourceforge.pinyin4j.PinyinHelper;  
  6. import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;  
  7. import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;  
  8. import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;  
  9. import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;  
  10.   
  11. import org.apache.lucene.analysis.TokenFilter;  
  12. import org.apache.lucene.analysis.TokenStream;  
  13. import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;  
  14. /** 
  15.  * 拼音过滤器[负责将汉字转换为拼音] 
  16.  * @author Lanxiaowei 
  17.  * 
  18.  */  
  19. public class PinyinTokenFilter extends TokenFilter {  
  20.     private final CharTermAttribute termAtt;  
  21.     /**汉语拼音输出转换器[基于Pinyin4j]*/  
  22.     private HanyuPinyinOutputFormat outputFormat;  
  23.     /**对于多音字会有多个拼音,firstChar即表示只取第一个,否则会取多个拼音*/  
  24.     private boolean firstChar;  
  25.     /**Term最小长度[小于这个最小长度的不进行拼音转换]*/  
  26.     private int minTermLength;  
  27.     private char[] curTermBuffer;  
  28.     private int curTermLength;  
  29.     private boolean outChinese;  
  30.   
  31.     public PinyinTokenFilter(TokenStream input) {  
  32.         this(input, Constant.DEFAULT_FIRST_CHAR, Constant.DEFAULT_MIN_TERM_LRNGTH);  
  33.     }  
  34.   
  35.     public PinyinTokenFilter(TokenStream input, boolean firstChar) {  
  36.         this(input, firstChar, Constant.DEFAULT_MIN_TERM_LRNGTH);  
  37.     }  
  38.   
  39.     public PinyinTokenFilter(TokenStream input, boolean firstChar,  
  40.             int minTermLenght) {  
  41.         this(input, firstChar, minTermLenght, Constant.DEFAULT_NGRAM_CHINESE);  
  42.     }  
  43.   
  44.     public PinyinTokenFilter(TokenStream input, boolean firstChar,  
  45.             int minTermLenght, boolean outChinese) {  
  46.         super(input);  
  47.   
  48.         this.termAtt = ((CharTermAttribute) addAttribute(CharTermAttribute.class));  
  49.         this.outputFormat = new HanyuPinyinOutputFormat();  
  50.         this.firstChar = false;  
  51.         this.minTermLength = Constant.DEFAULT_MIN_TERM_LRNGTH;  
  52.   
  53.         this.outChinese = Constant.DEFAULT_OUT_CHINESE;  
  54.   
  55.         this.firstChar = firstChar;  
  56.         this.minTermLength = minTermLenght;  
  57.         if (this.minTermLength < 1) {  
  58.             this.minTermLength = 1;  
  59.         }  
  60.         this.outputFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);  
  61.         this.outputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);  
  62.     }  
  63.   
  64.     public static boolean containsChinese(String s) {  
  65.         if ((s == null) || ("".equals(s.trim())))  
  66.             return false;  
  67.         for (int i = 0; i < s.length(); i++) {  
  68.             if (isChinese(s.charAt(i)))  
  69.                 return true;  
  70.         }  
  71.         return false;  
  72.     }  
  73.   
  74.     public static boolean isChinese(char a) {  
  75.         int v = a;  
  76.         return (v >= 19968) && (v <= 171941);  
  77.     }  
  78.   
  79.     public final boolean incrementToken() throws IOException {  
  80.         while (true) {  
  81.             if (this.curTermBuffer == null) {  
  82.                 if (!this.input.incrementToken()) {  
  83.                     return false;  
  84.                 }  
  85.                 this.curTermBuffer = ((char[]) this.termAtt.buffer().clone());  
  86.                 this.curTermLength = this.termAtt.length();  
  87.             }  
  88.   
  89.             if (this.outChinese) {  
  90.                 this.outChinese = false;  
  91.                 this.termAtt.copyBuffer(this.curTermBuffer, 0,  
  92.                         this.curTermLength);  
  93.                 return true;  
  94.             }  
  95.             this.outChinese = true;  
  96.             String chinese = this.termAtt.toString();  
  97.   
  98.             if (containsChinese(chinese)) {  
  99.                 this.outChinese = true;  
  100.                 if (chinese.length() >= this.minTermLength) {  
  101.                     try {  
  102.                         String chineseTerm = getPinyinString(chinese);  
  103.                         this.termAtt.copyBuffer(chineseTerm.toCharArray(), 0,  
  104.                                 chineseTerm.length());  
  105.                     } catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) {  
  106.                         badHanyuPinyinOutputFormatCombination.printStackTrace();  
  107.                     }  
  108.                     this.curTermBuffer = null;  
  109.                     return true;  
  110.                 }  
  111.   
  112.             }  
  113.   
  114.             this.curTermBuffer = null;  
  115.         }  
  116.     }  
  117.   
  118.     public void reset() throws IOException {  
  119.         super.reset();  
  120.     }  
  121.   
  122.     private String getPinyinString(String chinese)  
  123.             throws BadHanyuPinyinOutputFormatCombination {  
  124.         String chineseTerm = null;  
  125.         if (this.firstChar) {  
  126.             StringBuilder sb = new StringBuilder();  
  127.             for (int i = 0; i < chinese.length(); i++) {  
  128.                 String[] array = PinyinHelper.toHanyuPinyinStringArray(  
  129.                         chinese.charAt(i), this.outputFormat);  
  130.                 if ((array != null) && (array.length != 0)) {  
  131.                     String s = array[0];  
  132.                     char c = s.charAt(0);  
  133.   
  134.                     sb.append(c);  
  135.                 }  
  136.             }  
  137.             chineseTerm = sb.toString();  
  138.         } else {  
  139.             chineseTerm = PinyinHelper.toHanyuPinyinString(chinese,  
  140.                     this.outputFormat, "");  
  141.         }  
  142.         return chineseTerm;  
  143.     }  
  144. }  

    

Java代码   收藏代码
  1. package com.yida.framework.lucene5.pinyin;  
  2.   
  3. import java.io.IOException;  
  4. import org.apache.lucene.analysis.TokenFilter;  
  5. import org.apache.lucene.analysis.TokenStream;  
  6. import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;  
  7. import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;  
  8. /** 
  9.  * 对转换后的拼音进行NGram处理的TokenFilter 
  10.  * @author Lanxiaowei 
  11.  * 
  12.  */  
  13. public class PinyinNGramTokenFilter extends TokenFilter {  
  14.     public static final boolean DEFAULT_NGRAM_CHINESE = false;  
  15.     private final int minGram;  
  16.     private final int maxGram;  
  17.     /**是否需要对中文进行NGram[默认为false]*/  
  18.     private final boolean nGramChinese;  
  19.     private final CharTermAttribute termAtt;  
  20.     private final OffsetAttribute offsetAtt;  
  21.     private char[] curTermBuffer;  
  22.     private int curTermLength;  
  23.     private int curGramSize;  
  24.     private int tokStart;  
  25.   
  26.     public PinyinNGramTokenFilter(TokenStream input) {  
  27.         this(input, Constant.DEFAULT_MIN_GRAM, Constant.DEFAULT_MAX_GRAM, DEFAULT_NGRAM_CHINESE);  
  28.     }  
  29.       
  30.     public PinyinNGramTokenFilter(TokenStream input, int maxGram) {  
  31.         this(input, Constant.DEFAULT_MIN_GRAM, maxGram, DEFAULT_NGRAM_CHINESE);  
  32.     }  
  33.       
  34.     public PinyinNGramTokenFilter(TokenStream input, int minGram, int maxGram) {  
  35.         this(input, minGram, maxGram, DEFAULT_NGRAM_CHINESE);  
  36.     }  
  37.   
  38.     public PinyinNGramTokenFilter(TokenStream input, int minGram, int maxGram,  
  39.             boolean nGramChinese) {  
  40.         super(input);  
  41.   
  42.         this.termAtt = ((CharTermAttribute) addAttribute(CharTermAttribute.class));  
  43.         this.offsetAtt = ((OffsetAttribute) addAttribute(OffsetAttribute.class));  
  44.   
  45.         if (minGram < 1) {  
  46.             throw new IllegalArgumentException(  
  47.                     "minGram must be greater than zero");  
  48.         }  
  49.         if (minGram > maxGram) {  
  50.             throw new IllegalArgumentException(  
  51.                     "minGram must not be greater than maxGram");  
  52.         }  
  53.         this.minGram = minGram;  
  54.         this.maxGram = maxGram;  
  55.         this.nGramChinese = nGramChinese;  
  56.     }  
  57.   
  58.     public static boolean containsChinese(String s) {  
  59.         if ((s == null) || ("".equals(s.trim())))  
  60.             return false;  
  61.         for (int i = 0; i < s.length(); i++) {  
  62.             if (isChinese(s.charAt(i)))  
  63.                 return true;  
  64.         }  
  65.         return false;  
  66.     }  
  67.   
  68.     public static boolean isChinese(char a) {  
  69.         int v = a;  
  70.         return (v >= 19968) && (v <= 171941);  
  71.     }  
  72.   
  73.     public final boolean incrementToken() throws IOException {  
  74.         while (true) {  
  75.             if (this.curTermBuffer == null) {  
  76.                 if (!this.input.incrementToken()) {  
  77.                     return false;  
  78.                 }  
  79.                 if ((!this.nGramChinese)  
  80.                         && (containsChinese(this.termAtt.toString()))) {  
  81.                     return true;  
  82.                 }  
  83.                 this.curTermBuffer = ((char[]) this.termAtt.buffer().clone());  
  84.   
  85.                 this.curTermLength = this.termAtt.length();  
  86.                 this.curGramSize = this.minGram;  
  87.                 this.tokStart = this.offsetAtt.startOffset();  
  88.             }  
  89.   
  90.             if (this.curGramSize <= this.maxGram) {  
  91.                 if (this.curGramSize >= this.curTermLength) {  
  92.                     clearAttributes();  
  93.                     this.offsetAtt.setOffset(this.tokStart + 0this.tokStart  
  94.                             + this.curTermLength);  
  95.                     this.termAtt.copyBuffer(this.curTermBuffer, 0,  
  96.                             this.curTermLength);  
  97.                     this.curTermBuffer = null;  
  98.                     return true;  
  99.                 }  
  100.                 int start = 0;  
  101.                 int end = start + this.curGramSize;  
  102.                 clearAttributes();  
  103.                 this.offsetAtt.setOffset(this.tokStart + start, this.tokStart  
  104.                         + end);  
  105.                 this.termAtt.copyBuffer(this.curTermBuffer, start,  
  106.                         this.curGramSize);  
  107.                 this.curGramSize += 1;  
  108.                 return true;  
  109.             }  
  110.   
  111.             this.curTermBuffer = null;  
  112.         }  
  113.     }  
  114.   
  115.     public void reset() throws IOException {  
  116.         super.reset();  
  117.         this.curTermBuffer = null;  
  118.     }  
  119. }  

    

Java代码   收藏代码
  1. package com.yida.framework.lucene5.pinyin;  
  2.   
  3. import java.io.BufferedReader;  
  4. import java.io.Reader;  
  5. import java.io.StringReader;  
  6.   
  7. import org.apache.lucene.analysis.Analyzer;  
  8. import org.apache.lucene.analysis.TokenStream;  
  9. import org.apache.lucene.analysis.Tokenizer;  
  10. import org.apache.lucene.analysis.core.LowerCaseFilter;  
  11. import org.apache.lucene.analysis.core.StopAnalyzer;  
  12. import org.apache.lucene.analysis.core.StopFilter;  
  13. import org.wltea.analyzer.lucene.IKTokenizer;  
  14. /** 
  15.  * 自定义拼音分词器 
  16.  * @author Lanxiaowei 
  17.  * 
  18.  */  
  19. public class PinyinAnalyzer extends Analyzer {  
  20.     private int minGram;  
  21.     private int maxGram;  
  22.     private boolean useSmart;  
  23.       
  24.     public PinyinAnalyzer() {  
  25.         super();  
  26.         this.maxGram = Constant.DEFAULT_MAX_GRAM;  
  27.         this.minGram = Constant.DEFAULT_MIN_GRAM;  
  28.         this.useSmart = Constant.DEFAULT_IK_USE_SMART;  
  29.     }  
  30.       
  31.     public PinyinAnalyzer(boolean useSmart) {  
  32.         super();  
  33.         this.maxGram = Constant.DEFAULT_MAX_GRAM;  
  34.         this.minGram = Constant.DEFAULT_MIN_GRAM;  
  35.         this.useSmart = useSmart;  
  36.     }  
  37.       
  38.     public PinyinAnalyzer(int maxGram) {  
  39.         super();  
  40.         this.maxGram = maxGram;  
  41.         this.minGram = Constant.DEFAULT_MIN_GRAM;  
  42.         this.useSmart = Constant.DEFAULT_IK_USE_SMART;  
  43.     }  
  44.   
  45.     public PinyinAnalyzer(int maxGram,boolean useSmart) {  
  46.         super();  
  47.         this.maxGram = maxGram;  
  48.         this.minGram = Constant.DEFAULT_MIN_GRAM;  
  49.         this.useSmart = useSmart;  
  50.     }  
  51.   
  52.     public PinyinAnalyzer(int minGram, int maxGram,boolean useSmart) {  
  53.         super();  
  54.         this.minGram = minGram;  
  55.         this.maxGram = maxGram;  
  56.         this.useSmart = useSmart;  
  57.     }  
  58.   
  59.     @Override  
  60.     protected TokenStreamComponents createComponents(String fieldName) {  
  61.         Reader reader = new BufferedReader(new StringReader(fieldName));  
  62.         Tokenizer tokenizer = new IKTokenizer(reader, useSmart);  
  63.         //转拼音  
  64.         TokenStream tokenStream = new PinyinTokenFilter(tokenizer,   
  65.             Constant.DEFAULT_FIRST_CHAR, Constant.DEFAULT_MIN_TERM_LRNGTH);  
  66.         //对拼音进行NGram处理  
  67.         tokenStream = new PinyinNGramTokenFilter(tokenStream, this.minGram, this.maxGram);  
  68.         tokenStream = new LowerCaseFilter(tokenStream);  
  69.         tokenStream = new StopFilter(tokenStream,StopAnalyzer.ENGLISH_STOP_WORDS_SET);  
  70.         return new Analyzer.TokenStreamComponents(tokenizer, tokenStream);  
  71.     }  
  72. }  

    

Java代码   收藏代码
  1. package com.yida.framework.lucene5.pinyin.test;  
  2.   
  3. import java.io.IOException;  
  4.   
  5. import org.apache.lucene.analysis.Analyzer;  
  6.   
  7. import com.yida.framework.lucene5.pinyin.PinyinAnalyzer;  
  8. import com.yida.framework.lucene5.util.AnalyzerUtils;  
  9.   
  10. /** 
  11.  * 拼音分词器测试 
  12.  * @author Lanxiaowei 
  13.  * 
  14.  */  
  15. public class PinyinAnalyzerTest {  
  16.     public static void main(String[] args) throws IOException {  
  17.         String text = "2011年3月31日,孙燕姿与相恋5年多的男友纳迪姆在新加坡登记结婚";  
  18.         Analyzer analyzer = new PinyinAnalyzer(20);  
  19.         AnalyzerUtils.displayTokens(analyzer, text);  
  20.     }  
  21. }  

    

Java代码   收藏代码
  1. package com.yida.framework.lucene5.pinyin.test;  
  2.   
  3. import org.apache.lucene.analysis.Analyzer;  
  4. import org.apache.lucene.document.Document;  
  5. import org.apache.lucene.document.Field.Store;  
  6. import org.apache.lucene.document.TextField;  
  7. import org.apache.lucene.index.DirectoryReader;  
  8. import org.apache.lucene.index.IndexReader;  
  9. import org.apache.lucene.index.IndexWriter;  
  10. import org.apache.lucene.index.IndexWriterConfig;  
  11. import org.apache.lucene.index.Term;  
  12. import org.apache.lucene.search.IndexSearcher;  
  13. import org.apache.lucene.search.Query;  
  14. import org.apache.lucene.search.ScoreDoc;  
  15. import org.apache.lucene.search.TermQuery;  
  16. import org.apache.lucene.search.TopDocs;  
  17. import org.apache.lucene.store.Directory;  
  18. import org.apache.lucene.store.RAMDirectory;  
  19.   
  20. import com.yida.framework.lucene5.pinyin.PinyinAnalyzer;  
  21.   
  22. /** 
  23.  * 拼音搜索测试 
  24.  * @author Lanxiaowei 
  25.  * 
  26.  */  
  27. public class PinyinSearchTest {  
  28.     public static void main(String[] args) throws Exception {  
  29.         String fieldName = "content";  
  30.         String queryString = "sunyanzi";  
  31.           
  32.         Directory directory = new RAMDirectory();  
  33.         Analyzer analyzer = new PinyinAnalyzer();  
  34.         IndexWriterConfig config = new IndexWriterConfig(analyzer);  
  35.         IndexWriter writer = new IndexWriter(directory, config);  
  36.           
  37.         /****************创建测试索引begin********************/  
  38.         Document doc1 = new Document();  
  39.         doc1.add(new TextField(fieldName, "孙燕姿,新加坡籍华语流行音乐女歌手,刚出道便被誉为华语“四小天后”之一。", Store.YES));  
  40.         writer.addDocument(doc1);  
  41.           
  42.         Document doc2 = new Document();  
  43.         doc2.add(new TextField(fieldName, "1978年7月23日,孙燕姿出生于新加坡,祖籍中国广东省潮州市,父亲孙耀宏是新加坡南洋理工大学电机系教授,母亲是一名教师。姐姐孙燕嘉比燕姿大三岁,任职新加坡巴克莱投资银行副总裁,妹妹孙燕美小六岁,是新加坡国立大学医学硕士,燕姿作为家中的第二个女儿,次+女=姿,故取名“燕姿”", Store.YES));  
  44.         writer.addDocument(doc2);  
  45.           
  46.         Document doc3 = new Document();  
  47.         doc3.add(new TextField(fieldName, "孙燕姿毕业于新加坡南洋理工大学,父亲是燕姿音乐的启蒙者,燕姿从小热爱音乐,五岁开始学钢琴,十岁第一次在舞台上唱歌,十八岁写下第一首自己作词作曲的歌《Someone》。", Store.YES));  
  48.         writer.addDocument(doc3);  
  49.           
  50.         Document doc4 = new Document();  
  51.         doc4.add(new TextField(fieldName, "华纳音乐于2000年6月9日推出孙燕姿的首张音乐专辑《孙燕姿同名专辑》,孙燕姿由此开始了她的音乐之旅。", Store.YES));  
  52.         writer.addDocument(doc4);  
  53.           
  54.         Document doc5 = new Document();  
  55.         doc5.add(new TextField(fieldName, "2000年,孙燕姿的首张专辑《孙燕姿同名专辑》获得台湾地区年度专辑销售冠军,在台湾卖出30余万张的好成绩,同年底,发行第二张专辑《我要的幸福》", Store.YES));  
  56.         writer.addDocument(doc5);  
  57.           
  58.         Document doc6 = new Document();  
  59.         doc6.add(new TextField(fieldName, "2011年3月31日,孙燕姿与相恋5年多的男友纳迪姆在新加坡登记结婚", Store.YES));  
  60.         writer.addDocument(doc6);  
  61.           
  62.         //强制合并为1个段  
  63.         writer.forceMerge(1);  
  64.         writer.close();  
  65.         /****************创建测试索引end********************/  
  66.           
  67.         IndexReader reader = DirectoryReader.open(directory);  
  68.         IndexSearcher searcher = new IndexSearcher(reader);  
  69.         Query query = new TermQuery(new Term(fieldName,queryString));  
  70.         TopDocs topDocs = searcher.search(query,Integer.MAX_VALUE);  
  71.         ScoreDoc[] docs = topDocs.scoreDocs;  
  72.         if(null == docs || docs.length <= 0) {  
  73.             System.out.println("No results.");  
  74.             return;  
  75.         }  
  76.           
  77.         //打印查询结果  
  78.         System.out.println("ID[Score]\tcontent");  
  79.         for (ScoreDoc scoreDoc : docs) {  
  80.             int docID = scoreDoc.doc;  
  81.             Document document = searcher.doc(docID);  
  82.             String content = document.get(fieldName);  
  83.             float score = scoreDoc.score;  
  84.             System.out.println(docID + "[" + score + "]\t" + content);  
  85.         }  
  86.     }  
  87. }  

    我只贴出了比较核心的几个类,至于关联的其他类,请你们下载底下的附件再详细的看吧。拼音搜索就说这么多了,如果你还有什么问题,请QQ上联系我(QQ:7-3-6-0-3-1-3-0-5),或者加我的Java技术群跟我们一起交流学习,我会非常的欢迎的。群号:

 

转载:http://iamyida.iteye.com/blog/2207080

目录
相关文章
|
6天前
|
数据采集 存储 API
手动给docusaurus添加一个搜索
如果algolia不能自动配置的话,我教你手动给docusaurus添加一个搜索
手动给docusaurus添加一个搜索
|
自然语言处理 算法 搜索推荐
给全文搜索引擎Manticore (Sphinx) search 增加中文分词
Sphinx search 是一款非常棒的开源全文搜索引擎,它使用C++开发,索引和搜索的速度非常快,我使用sphinx的时间也有好多年了。最初使用的是coreseek,一个国人在sphinxsearch基础上添加了mmseg分词的搜索引擎,可惜后来不再更新,sphinxsearch的版本太低,bug也会出现;后来也使用最新的sphinxsearch,它可以支持几乎所有语言,通过其内置的ngram tokenizer对中文进行索引和搜索。
3851 0
|
9月前
|
关系型数据库 MySQL 索引
全文本搜索的使用说明
全文本搜索的使用说明
68 0
|
9月前
|
Web App开发 搜索推荐 Windows
一键搜索多个搜索引擎
一键搜索多个搜索引擎
145 0
|
数据采集 搜索推荐 前端开发
11、搜索服务
根据分类、关键字匹配课程名称,课程内容、难度等级搜索,搜索方式为全文搜索,搜索节点分页显示。
65 0
|
搜索推荐 安全 Java
搜索
搜索
81 0
|
自然语言处理 索引
Elasticsearch添加拼音搜索支持
Elasticsearch添加拼音搜索支持
188 0
|
自然语言处理 索引
solr长文本搜索问题
假期重新把之前在新浪博客里面的文字梳理了下,搬到这里
239 0
|
机器学习/深度学习 算法 搜索推荐
DARTS+:DARTS 搜索为何需要早停?
近日,华为诺亚 方舟实验室的作者们提出一种可微分的神经网络架构搜索算法 DARTS+,将早停机制(early stopping)引入到原始的 DARTS[1] 算法中,不仅减小了 DARTS 搜索的时间,而且极大地提升了 DARTS 的性能。相关论文《DARTS+: Improved Differentiable Architecture Search with Early Stopping》已经公开(相关代码稍后也会开源)。
185 0
DARTS+:DARTS 搜索为何需要早停?

热门文章

最新文章