Skip to content

Commit

Permalink
支持elasticsearch-5.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ysc committed Oct 25, 2017
1 parent 66647fd commit cca78c7
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 285 deletions.
40 changes: 1 addition & 39 deletions pom.xml
Expand Up @@ -126,7 +126,7 @@
<slf4j-api.version>1.6.4</slf4j-api.version>
<logback-classic.version>0.9.28</logback-classic.version>
<lucene.version>5.4.0</lucene.version>
<elasticsearch.version>2.1.1</elasticsearch.version>
<elasticsearch.version>5.4.3</elasticsearch.version>
<jedis.version>2.5.1</jedis.version>
<pinyin4j.version>2.5.0</pinyin4j.version>
</properties>
Expand Down Expand Up @@ -241,44 +241,6 @@
</exclusion>
</exclusions>
</dependency>
<!-- elasticsearch测试依赖 -->
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${elasticsearch.version}</version>
<type>test-jar</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-memory</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-highlighter</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-suggest</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-misc</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-join</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-grouping</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-spatial</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- redis客户端库 -->
<dependency>
<groupId>redis.clients</groupId>
Expand Down

This file was deleted.

@@ -1,59 +1,39 @@
/**
*
* APDPlat - Application Product Development Platform
* Copyright (c) 2013, 杨尚川, yang-shangchuan@qq.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package org.apdplat.word.elasticsearch;

import org.apdplat.word.lucene.ChineseWordAnalyzer;
import org.apdplat.word.segmentation.Segmentation;
import org.apdplat.word.segmentation.SegmentationAlgorithm;
import org.apdplat.word.segmentation.SegmentationFactory;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.assistedinject.Assisted;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractIndexAnalyzerProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* 中文分析器工厂
* @author 杨尚川
* Created by ysc on 25/10/2017.
*/
public class ChineseWordAnalyzerProvider extends AbstractIndexAnalyzerProvider<ChineseWordAnalyzer> {
private static final Logger LOGGER = LoggerFactory.getLogger(ChineseWordAnalyzerProvider.class);

private final ChineseWordAnalyzer analyzer;
@Inject
public ChineseWordAnalyzerProvider(Index index, Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) {
super(index, indexSettings, name, settings);
private final Segmentation segmentation;

public ChineseWordAnalyzerProvider(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
super(indexSettings, name, settings);
String segAlgorithm = settings.get("segAlgorithm");
if(segAlgorithm != null){
LOGGER.info("analyzer使用指定分词算法:"+segAlgorithm);
Segmentation segmentation = SegmentationFactory.getSegmentation(SegmentationAlgorithm.valueOf(segAlgorithm));
analyzer = new ChineseWordAnalyzer(segmentation);
LOGGER.info("tokenizer使用指定分词算法:"+segAlgorithm);
segmentation = SegmentationFactory.getSegmentation(SegmentationAlgorithm.valueOf(segAlgorithm));
}else{
LOGGER.info("没有为word analyzer指定segAlgorithm参数");
LOGGER.info("analyzer使用默认分词算法:"+SegmentationAlgorithm.BidirectionalMaximumMatching);
analyzer = new ChineseWordAnalyzer();
LOGGER.info("没有为word tokenizer指定segAlgorithm参数");
LOGGER.info("tokenizer使用默认分词算法:"+SegmentationAlgorithm.MaxNgramScore);
segmentation = SegmentationFactory.getSegmentation(SegmentationAlgorithm.MaxNgramScore);
}
analyzer = new ChineseWordAnalyzer(segmentation);
}

@Override
public ChineseWordAnalyzer get() {
return this.analyzer;
Expand Down

This file was deleted.

This file was deleted.

@@ -0,0 +1,22 @@
package org.apdplat.word.elasticsearch;

import org.apache.lucene.analysis.TokenStream;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractTokenFilterFactory;

/**
* Created by ysc on 25/10/2017.
*/
public class ChineseWordNoOpTokenFilterFactory extends AbstractTokenFilterFactory {

public ChineseWordNoOpTokenFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
super(indexSettings, name, settings);
}

@Override
public TokenStream create(TokenStream tokenStream) {
return tokenStream;
}
}

0 comments on commit cca78c7

Please sign in to comment.