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

Commit 32761b9

Browse files
committed
1.4.0.2
1 parent 1368fbe commit 32761b9

17 files changed

+401
-47
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ zh-tw
8383

8484
| Elasticsearch | Plugin | Release date |
8585
| -------------- | -------------- | ------------ |
86+
| 1.4.0 | 1.4.0.2 | Nov 26, 2014 |
8687
| 1.4.0 | 1.4.0.1 | Nov 20, 2014 |
8788
| 1.4.0 | 1.4.0.0 | Nov 14, 2014 |
8889
| 1.3.1 | 1.3.0.0 | Jul 30, 2014 |
@@ -91,14 +92,15 @@ zh-tw
9192

9293
## Installation
9394

94-
./bin/plugin -install langdetect -url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-langdetect/1.4.0.1/elasticsearch-langdetect-1.4.0.1-plugin.zip
95+
./bin/plugin -install langdetect -url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-langdetect/1.4.0.2/elasticsearch-langdetect-1.4.0.2-plugin.zip
9596

9697
Do not forget to restart the node after installing.
9798

9899
## Checksum
99100

100101
| File | SHA1 |
101102
| --------------------------------------------- | -----------------------------------------|
103+
| elasticsearch-langdetect-1.4.0.2-plugin.zip | 60919142f12d8b54e519f6cf97862e842c6b3bb8 |
102104
| elasticsearch-langdetect-1.4.0.1-plugin.zip | a7ab2401ae68789bf1e5841427ce40440c903da4 |
103105
| elasticsearch-langdetect-1.4.0.0-plugin.zip | f95361fa1a81b2681e2e9002b03ca6aad57f3012 |
104106
| elasticsearch-langdetect-1.3.0.0-plugin.zip | e2dd56c72f19cec861141becd8beb18d7bb26ee6 |
@@ -246,7 +248,7 @@ All feedback is welcome! If you find issues, please post them at [Github](https:
246248

247249
curl -XPOST 'localhost:9200/_langdetect?pretty' -d 'This is a test'
248250
{
249-
"ok" : true,
251+
"profile" : "/langdetect/",
250252
"languages" : [ {
251253
"language" : "en",
252254
"probability" : 0.9999971603535163
@@ -255,7 +257,7 @@ All feedback is welcome! If you find issues, please post them at [Github](https:
255257

256258
curl -XPOST 'localhost:9200/_langdetect?pretty' -d 'Das ist ein Test'
257259
{
258-
"ok" : true,
260+
"profile" : "/langdetect/",
259261
"languages" : [ {
260262
"language" : "de",
261263
"probability" : 0.9999993070517024
@@ -264,7 +266,7 @@ All feedback is welcome! If you find issues, please post them at [Github](https:
264266

265267
curl -XPOST 'localhost:9200/_langdetect?pretty' -d 'Datt isse ne test'
266268
{
267-
"ok" : true,
269+
"profile" : "/langdetect/",
268270
"languages" : [ {
269271
"language" : "no",
270272
"probability" : 0.5714251911820175
@@ -277,6 +279,9 @@ All feedback is welcome! If you find issues, please post them at [Github](https:
277279
} ]
278280
}
279281

282+
## Change profile of language detection to "shart text" profile
283+
284+
curl -XPOST 'localhost:9200/_langdetect/profile?profile=/langdetect/short-text/'
280285

281286
# Credits
282287

pom.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>org.xbib.elasticsearch.plugin</groupId>
99
<artifactId>elasticsearch-langdetect</artifactId>
10-
<version>1.4.0.1</version>
10+
<version>1.4.0.2</version>
1111

1212
<packaging>jar</packaging>
1313

@@ -99,6 +99,20 @@
9999
<scope>test</scope>
100100
</dependency>
101101

102+
<dependency>
103+
<groupId>org.apache.logging.log4j</groupId>
104+
<artifactId>log4j-slf4j-impl</artifactId>
105+
<version>2.0</version>
106+
<scope>test</scope>
107+
</dependency>
108+
109+
<dependency>
110+
<groupId>org.apache.logging.log4j</groupId>
111+
<artifactId>log4j-core</artifactId>
112+
<version>2.0</version>
113+
<scope>test</scope>
114+
</dependency>
115+
102116
</dependencies>
103117

104118
<build>

src/main/java/org/xbib/elasticsearch/action/langdetect/LangdetectResponse.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,22 @@
1313

1414
public class LangdetectResponse extends ActionResponse implements StatusToXContent {
1515

16+
private String profile;
17+
1618
private List<Language> languages;
1719

1820
public LangdetectResponse() {
1921
}
2022

23+
public LangdetectResponse setProfile(String profile) {
24+
this.profile = profile;
25+
return this;
26+
}
27+
28+
public String getProfile() {
29+
return profile;
30+
}
31+
2132
public LangdetectResponse setLanguages(List<Language> languages) {
2233
this.languages = languages;
2334
return this;
@@ -29,6 +40,7 @@ public List<Language> getLanguages() {
2940

3041
@Override
3142
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
43+
builder.field("profile", profile);
3244
builder.startArray("languages");
3345
for (Language lang : languages) {
3446
builder.startObject().field("language", lang.getLanguage())

src/main/java/org/xbib/elasticsearch/action/langdetect/TransportLangdetectAction.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ public TransportLangdetectAction(Settings settings, ThreadPool threadPool,
2121
ActionFilters actionFilters, LangdetectService service) {
2222
super(settings, LangdetectAction.NAME, threadPool, actionFilters);
2323
this.service = service;
24-
// start the service here
25-
this.service.start();
2624
}
2725

2826
@Override
2927
protected void doExecute(LangdetectRequest request, ActionListener<LangdetectResponse> listener) {
3028
try {
3129
List<Language> langs = service.detectAll(request.getText());
32-
listener.onResponse(new LangdetectResponse().setLanguages(langs));
30+
listener.onResponse(new LangdetectResponse().setLanguages(langs).setProfile(service.getProfile()));
3331
} catch (LanguageDetectionException e) {
3432
listener.onFailure(e);
3533
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.xbib.elasticsearch.action.langdetect.profile;
2+
3+
import org.elasticsearch.action.admin.indices.IndicesAction;
4+
import org.elasticsearch.client.IndicesAdminClient;
5+
6+
public class LangdetectProfileAction extends IndicesAction<LangdetectProfileRequest, LangdetectProfileResponse, LangdetectProfileRequestBuilder> {
7+
8+
public static final String NAME = "langdetect.profile";
9+
10+
public static final LangdetectProfileAction INSTANCE = new LangdetectProfileAction();
11+
12+
private LangdetectProfileAction() {
13+
super(NAME);
14+
}
15+
16+
@Override
17+
public LangdetectProfileRequestBuilder newRequestBuilder(IndicesAdminClient client) {
18+
return new LangdetectProfileRequestBuilder(client);
19+
}
20+
21+
@Override
22+
public LangdetectProfileResponse newResponse() {
23+
return new LangdetectProfileResponse();
24+
}
25+
26+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.xbib.elasticsearch.action.langdetect.profile;
2+
3+
import org.elasticsearch.action.support.single.custom.SingleCustomOperationRequest;
4+
import org.elasticsearch.common.io.stream.StreamInput;
5+
import org.elasticsearch.common.io.stream.StreamOutput;
6+
7+
import java.io.IOException;
8+
9+
public class LangdetectProfileRequest extends SingleCustomOperationRequest<LangdetectProfileRequest> {
10+
11+
private String profile;
12+
13+
public LangdetectProfileRequest() {
14+
}
15+
16+
public LangdetectProfileRequest setProfile(String profile) {
17+
this.profile = profile;
18+
return this;
19+
}
20+
21+
public String getProfile() {
22+
return profile;
23+
}
24+
25+
@Override
26+
public void readFrom(StreamInput in) throws IOException {
27+
super.readFrom(in);
28+
profile = in.readString();
29+
}
30+
31+
@Override
32+
public void writeTo(StreamOutput out) throws IOException {
33+
super.writeTo(out);
34+
out.writeString(profile);
35+
}
36+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.xbib.elasticsearch.action.langdetect.profile;
2+
3+
import org.elasticsearch.action.ActionListener;
4+
import org.elasticsearch.action.support.single.custom.SingleCustomOperationRequestBuilder;
5+
import org.elasticsearch.client.IndicesAdminClient;
6+
7+
public class LangdetectProfileRequestBuilder extends SingleCustomOperationRequestBuilder<LangdetectProfileRequest, LangdetectProfileResponse, LangdetectProfileRequestBuilder> {
8+
9+
public LangdetectProfileRequestBuilder(IndicesAdminClient client) {
10+
super(client, new LangdetectProfileRequest());
11+
}
12+
13+
public LangdetectProfileRequestBuilder setProfile(String string) {
14+
request.setProfile(string);
15+
return this;
16+
}
17+
18+
@Override
19+
protected void doExecute(ActionListener<LangdetectProfileResponse> listener) {
20+
client.execute(LangdetectProfileAction.INSTANCE, request, listener);
21+
}
22+
23+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.xbib.elasticsearch.action.langdetect.profile;
2+
3+
import org.elasticsearch.action.ActionResponse;
4+
import org.elasticsearch.common.xcontent.StatusToXContent;
5+
import org.elasticsearch.common.xcontent.XContentBuilder;
6+
import org.elasticsearch.rest.RestStatus;
7+
8+
import java.io.IOException;
9+
10+
import static org.elasticsearch.rest.RestStatus.OK;
11+
12+
public class LangdetectProfileResponse extends ActionResponse implements StatusToXContent {
13+
14+
public LangdetectProfileResponse() {
15+
}
16+
17+
@Override
18+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
19+
builder.field("ok", true);
20+
return builder;
21+
}
22+
23+
@Override
24+
public RestStatus status() {
25+
return OK;
26+
}
27+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.xbib.elasticsearch.action.langdetect.profile;
2+
3+
import org.elasticsearch.action.ActionListener;
4+
import org.elasticsearch.action.support.ActionFilters;
5+
import org.elasticsearch.action.support.TransportAction;
6+
import org.elasticsearch.common.inject.Inject;
7+
import org.elasticsearch.common.settings.Settings;
8+
import org.elasticsearch.threadpool.ThreadPool;
9+
import org.xbib.elasticsearch.index.analysis.langdetect.LanguageDetectionException;
10+
import org.xbib.elasticsearch.module.langdetect.LangdetectService;
11+
12+
public class TransportLangdetectProfileAction extends TransportAction<LangdetectProfileRequest, LangdetectProfileResponse> {
13+
14+
private final LangdetectService service;
15+
16+
@Inject
17+
public TransportLangdetectProfileAction(Settings settings, ThreadPool threadPool,
18+
ActionFilters actionFilters, LangdetectService service) {
19+
super(settings, LangdetectProfileAction.NAME, threadPool, actionFilters);
20+
this.service = service;
21+
}
22+
23+
@Override
24+
protected void doExecute(LangdetectProfileRequest request, ActionListener<LangdetectProfileResponse> listener) {
25+
try {
26+
service.setProfile(request.getProfile());
27+
listener.onResponse(new LangdetectProfileResponse());
28+
} catch (LanguageDetectionException e) {
29+
listener.onFailure(e);
30+
}
31+
}
32+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.xbib.elasticsearch.module.langdetect;
2+
3+
import org.elasticsearch.common.inject.Binder;
4+
import org.elasticsearch.common.inject.Module;
5+
6+
public class LangdetectIndexModule implements Module {
7+
8+
@Override
9+
public void configure(Binder binder) {
10+
binder.bind(RegisterLangdetectType.class).asEagerSingleton();
11+
}
12+
13+
}

src/main/java/org/xbib/elasticsearch/module/langdetect/LangdetectModule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class LangdetectModule implements Module {
77

88
@Override
99
public void configure(Binder binder) {
10-
binder.bind(RegisterLangdetectType.class).asEagerSingleton();
10+
binder.bind(LangdetectService.class).asEagerSingleton();
1111
}
12+
1213
}

0 commit comments

Comments
 (0)