Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

Commit

Permalink
update to Elasticsearch 1.4, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jprante committed Nov 14, 2014
1 parent 308c5ac commit 1439e37
Show file tree
Hide file tree
Showing 96 changed files with 1,291 additions and 1,094 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,24 @@ zh-tw

![Travis](https://travis-ci.org/jprante/elasticsearch-langdetect.png)

| Elasticsearch | Plugin | Release date |
| Elasticsearch | Plugin | Release date |
| -------------- | -------------- | ------------ |
| 1.4.0 | 1.4.0.0 | Nov 14, 2014 |
| 1.3.1 | 1.3.0.0 | Jul 30, 2014 |
| 1.2.1 | 1.2.1.1 | Jun 18, 2014 |


## Installation

./bin/plugin -install langdetect -url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-langdetect/1.3.0.0/elasticsearch-langdetect-1.3.0.0-plugin.zip
./bin/plugin -install langdetect -url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-langdetect/1.4.0.0/elasticsearch-langdetect-1.4.0.0-plugin.zip

Do not forget to restart the node after installing.

## Checksum

| File | SHA1 |
| --------------------------------------------- | -----------------------------------------|
| elasticsearch-langdetect-1.4.0.0-plugin.zip | f95361fa1a81b2681e2e9002b03ca6aad57f3012 |
| elasticsearch-langdetect-1.3.0.0-plugin.zip | e2dd56c72f19cec861141becd8beb18d7bb26ee6 |
| elasticsearch-langdetect-1.2.1.1-plugin.zip | cc3a0d5ccecf1210b96771dcb5c9935176e1cc35 |
| elasticsearch-langdetect-1.2.1.0.zip | c07b84e798e284ee238554c2b2bc065dfdb9114d |
Expand Down
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>org.xbib.elasticsearch.plugin</groupId>
<artifactId>elasticsearch-langdetect</artifactId>
<version>1.3.0.0</version>
<version>1.4.0.0</version>

<packaging>jar</packaging>

Expand Down Expand Up @@ -69,7 +69,8 @@
<github.global.server>github</github.global.server>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.compiler.version>1.7</java.compiler.version>
<elasticsearch.version>1.3.1</elasticsearch.version>
<elasticsearch.version>1.4.0</elasticsearch.version>
<jackson.version>2.4.2</jackson.version>
</properties>

<dependencies>
Expand All @@ -85,15 +86,15 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.1</version>
<version>${jackson.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<type>jar</type>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -141,7 +142,6 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<skipTests>false</skipTests>
<includes>
<include>**/*Test.java</include>
</includes>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
package org.xbib.elasticsearch.action.langdetect;

import org.elasticsearch.action.support.single.custom.SingleCustomOperationRequest;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;

import java.io.IOException;

public class LangdetectRequest extends SingleCustomOperationRequest<LangdetectRequest> {

BytesReference text;
String text;

public LangdetectRequest() {
}

public LangdetectRequest setText(BytesReference text) {
public LangdetectRequest setText(String text) {
this.text = text;
return this;
}

public BytesReference getText() {
public String getText() {
return text;
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
text = in.readBytesReference();
text = in.readString();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeBytesReference(text);
out.writeString(text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public LangdetectRequestBuilder(IndicesAdminClient client) {
super(client, new LangdetectRequest());
}

public LangdetectRequestBuilder setText(String string) {
request.setText(string);
return this;
}

@Override
protected void doExecute(ActionListener<LangdetectResponse> listener) {
client.execute(LangdetectAction.INSTANCE, request, listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.elasticsearch.common.xcontent.StatusToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.RestStatus;
import org.xbib.elasticsearch.common.langdetect.Language;
import org.xbib.elasticsearch.index.analysis.langdetect.Language;

import java.io.IOException;
import java.util.List;
Expand All @@ -18,8 +18,9 @@ public class LangdetectResponse extends ActionResponse implements StatusToXConte
public LangdetectResponse() {
}

public LangdetectResponse(List<Language> languages) {
public LangdetectResponse setLanguages(List<Language> languages) {
this.languages = languages;
return this;
}

public List<Language> getLanguages() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,64 +1,37 @@
package org.xbib.elasticsearch.action.langdetect;

import org.elasticsearch.action.support.single.custom.TransportSingleCustomOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.routing.ShardsIterator;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.xbib.elasticsearch.common.langdetect.Detector;
import org.xbib.elasticsearch.common.langdetect.Language;
import org.xbib.elasticsearch.index.analysis.langdetect.Language;
import org.xbib.elasticsearch.index.analysis.langdetect.LanguageDetectionException;
import org.xbib.elasticsearch.module.langdetect.LangdetectService;

import java.util.List;

public class TransportLangdetectAction extends TransportSingleCustomOperationAction<LangdetectRequest, LangdetectResponse> {
public class TransportLangdetectAction extends TransportAction<LangdetectRequest, LangdetectResponse> {

private final Detector detector;
private final LangdetectService service;

@Inject
public TransportLangdetectAction(Settings settings, ThreadPool threadPool,
ClusterService clusterService, TransportService transportService) {
super(settings, LangdetectAction.NAME, threadPool, clusterService, transportService);
this.detector = new Detector(settings);
ActionFilters actionFilters, LangdetectService service) {
super(settings, LangdetectAction.NAME, threadPool, actionFilters);
this.service = service;
// start the service here
this.service.start();
}

@Override
protected String executor() {
return ThreadPool.Names.GENERIC;
}

@Override
protected ShardsIterator shards(ClusterState state, LangdetectRequest request) {
return null; // execute always locally
}

@Override
protected LangdetectRequest newRequest() {
return new LangdetectRequest();
}

@Override
protected LangdetectResponse newResponse() {
return new LangdetectResponse();
}

@Override
protected ClusterBlockException checkGlobalBlock(ClusterState state, LangdetectRequest request) {
return state.blocks().globalBlockedException(ClusterBlockLevel.READ);
}

@Override
protected ClusterBlockException checkRequestBlock(ClusterState state, LangdetectRequest request) {
return null; // no blocks
}

@Override
protected LangdetectResponse shardOperation(LangdetectRequest request, int shardId) {
List<Language> langs = detector.detectAll(request.getText().toUtf8());
return new LangdetectResponse(langs);
protected void doExecute(LangdetectRequest request, ActionListener<LangdetectResponse> listener) {
try {
List<Language> langs = service.detectAll(request.getText());
listener.onResponse(new LangdetectResponse().setLanguages(langs));
} catch (LanguageDetectionException e) {
listener.onFailure(e);
}
}
}
Loading

0 comments on commit 1439e37

Please sign in to comment.