Skip to content

Commit 1368fbe

Browse files
committed
settings in the mapping
1 parent 91e1b4b commit 1368fbe

File tree

5 files changed

+51
-10
lines changed

5 files changed

+51
-10
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,29 @@ zh-cn
7777
zh-tw
7878

7979

80-
8180
## Versions
8281

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

8584
| Elasticsearch | Plugin | Release date |
8685
| -------------- | -------------- | ------------ |
86+
| 1.4.0 | 1.4.0.1 | Nov 20, 2014 |
8787
| 1.4.0 | 1.4.0.0 | Nov 14, 2014 |
8888
| 1.3.1 | 1.3.0.0 | Jul 30, 2014 |
8989
| 1.2.1 | 1.2.1.1 | Jun 18, 2014 |
9090

9191

9292
## Installation
9393

94-
./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
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
9595

9696
Do not forget to restart the node after installing.
9797

9898
## Checksum
9999

100100
| File | SHA1 |
101101
| --------------------------------------------- | -----------------------------------------|
102+
| elasticsearch-langdetect-1.4.0.1-plugin.zip | a7ab2401ae68789bf1e5841427ce40440c903da4 |
102103
| elasticsearch-langdetect-1.4.0.0-plugin.zip | f95361fa1a81b2681e2e9002b03ca6aad57f3012 |
103104
| elasticsearch-langdetect-1.3.0.0-plugin.zip | e2dd56c72f19cec861141becd8beb18d7bb26ee6 |
104105
| elasticsearch-langdetect-1.2.1.1-plugin.zip | cc3a0d5ccecf1210b96771dcb5c9935176e1cc35 |

src/main/java/org/xbib/elasticsearch/index/mapper/langdetect/LangdetectMapper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public Builder lang(StringFieldMapper.Builder lang) {
5555
return this;
5656
}
5757

58+
public Builder profile(String profile) {
59+
settingsBuilder.put("profile", profile);
60+
return this;
61+
}
62+
5863
public Builder ntrials(int trials) {
5964
settingsBuilder.put("number_of_trials", trials);
6065
return this;
@@ -203,6 +208,10 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
203208
builder.languages((List<String>) fieldNode);
204209
break;
205210
}
211+
case "profile": {
212+
builder.profile((String) fieldNode);
213+
break;
214+
}
206215
}
207216
}
208217
return builder;

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class LangdetectService extends AbstractLifecycleComponent<LangdetectServ
2626
private final static Pattern word = Pattern.compile("[\\P{IsWord}]", Pattern.UNICODE_CHARACTER_CLASS);
2727

2828
private final static String[] DEFAULT_LANGUAGES = new String[] {
29-
"af",
29+
// "af",
3030
"ar",
3131
"bg",
3232
"bn",
@@ -48,27 +48,27 @@ public class LangdetectService extends AbstractLifecycleComponent<LangdetectServ
4848
"id",
4949
"it",
5050
"ja",
51-
"kn",
51+
// "kn",
5252
"ko",
5353
"lt",
5454
"lv",
5555
"mk",
5656
"ml",
57-
"mr",
58-
"ne",
57+
// "mr",
58+
// "ne",
5959
"nl",
6060
"no",
6161
"pa",
6262
"pl",
6363
"pt",
6464
"ro",
6565
"ru",
66-
"sk",
67-
"sl",
68-
"so",
66+
// "sk",
67+
//"sl",
68+
// "so",
6969
"sq",
7070
"sv",
71-
"sw",
71+
// "sw",
7272
"ta",
7373
"te",
7474
"th",

src/test/java/org/xbib/elasticsearch/index/mapper/langdetect/LangdetectMappingTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,27 @@ public void testBinary() throws Exception {
8080
assertEquals(doc.getFields("someField.lang")[0].stringValue(), "en");
8181
}
8282

83+
@Test
84+
public void testShortTextProfile() throws Exception {
85+
String mapping = copyToStringFromClasspath("short-text-mapping.json");
86+
DocumentMapper docMapper = createMapperParser().parse(mapping);
87+
String sampleText = copyToStringFromClasspath("english.txt");
88+
BytesReference json = jsonBuilder().startObject().field("_id", 1).field("someField", sampleText).endObject().bytes();
89+
ParseContext.Document doc = docMapper.parse(json).rootDoc();
90+
assertEquals(doc.get(docMapper.mappers().smartName("someField").mapper().names().indexName()), sampleText);
91+
assertEquals(doc.getFields("someField.lang").length, 1);
92+
assertEquals(doc.getFields("someField.lang")[0].stringValue(), "en");
93+
94+
// re-parse it
95+
String builtMapping = docMapper.mappingSource().string();
96+
docMapper = createMapperParser().parse(builtMapping);
97+
json = jsonBuilder().startObject().field("_id", 1).field("someField", sampleText).endObject().bytes();
98+
doc = docMapper.parse(json).rootDoc();
99+
assertEquals(doc.get(docMapper.mappers().smartName("someField").mapper().names().indexName()), sampleText);
100+
assertEquals(doc.getFields("someField.lang").length, 1);
101+
assertEquals(doc.getFields("someField.lang")[0].stringValue(), "en");
102+
}
103+
83104
private DocumentMapperParser createMapperParser() throws IOException {
84105
return createMapperParser(ImmutableSettings.EMPTY);
85106
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"someType" : {
3+
"properties" : {
4+
"someField" : {
5+
"type" : "langdetect",
6+
"profile" : "/langdetect/short-text/"
7+
}
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)