This repository has been archived by the owner on Dec 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update to Elasticsearch 1.4, refactoring
- Loading branch information
Showing
96 changed files
with
1,291 additions
and
1,094 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
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
11 changes: 5 additions & 6 deletions
11
src/main/java/org/xbib/elasticsearch/action/langdetect/LangdetectRequest.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 |
---|---|---|
@@ -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); | ||
} | ||
} |
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
67 changes: 20 additions & 47 deletions
67
src/main/java/org/xbib/elasticsearch/action/langdetect/TransportLangdetectAction.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 |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
Oops, something went wrong.