Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
repos
search-platform
elasticsearch-analysis-hebrew
Commits
2ede8de8
Commit
2ede8de8
authored
Dec 04, 2016
by
Itamar Syn-Hershko
Browse files
Supporting latest HebMorph release
parent
20749589
Changes
6
Hide whitespace changes
Inline
Side-by-side
plugin-descriptor.properties
View file @
2ede8de8
...
...
@@ -3,6 +3,6 @@ jvm=true
name
=
analysis-hebrew
description
=
Hebrew analyzer powered by HebMorph
classname
=
com.code972.elasticsearch.plugins.AnalysisPlugin
elasticsearch.version
=
2.3.5
java.version
=
1.
7
version
=
2.3.5
elasticsearch.version
=
5.0.0
java.version
=
1.
8
version
=
5.0.0
pom.xml
View file @
2ede8de8
...
...
@@ -9,14 +9,14 @@
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<lucene.version>
5.5.2
</lucene.version>
<elasticsearch.version>
2.4
.0
</elasticsearch.version>
<hebmorph.version>
2.4
.0
</hebmorph.version>
<lucene.version>
6.2.1
</lucene.version>
<elasticsearch.version>
5.0
.0
</elasticsearch.version>
<hebmorph.version>
6.0
.0
</hebmorph.version>
</properties>
<groupId>
com.code972.hebmorph
</groupId>
<artifactId>
elasticsearch-analysis-hebrew
</artifactId>
<version>
2.4
.0-SNAPSHOT
</version>
<version>
5.0
.0-SNAPSHOT
</version>
<packaging>
jar
</packaging>
<name>
elasticsearch-analysis-hebrew
</name>
<url>
http://code972.com/
</url>
...
...
src/main/java/com/code972/elasticsearch/plugins/AnalysisPlugin.java
View file @
2ede8de8
package
com.code972.elasticsearch.plugins
;
import
com.code972.elasticsearch.rest.action.RestHebrewAnalyzerCheckWordAction
;
import
com.code972.hebmorph.DictionaryLoader
;
import
com.code972.hebmorph.hspell.HSpellDictionaryLoader
;
import
com.google.common.reflect.Reflection
;
import
org.elasticsearch.common.settings.Settings
;
import
org.elasticsearch.index.analysis.AnalysisModule
;
import
org.elasticsearch.plugins.Plugin
;
...
...
@@ -13,14 +16,32 @@ public class AnalysisPlugin extends Plugin {
* If hebrew.dict.path is defined, try loading that.
*/
public
AnalysisPlugin
(
Settings
settings
)
{
final
DictionaryLoader
loader
;
// TODO try locating HebMorphDictionaryLoader
loader
=
new
HSpellDictionaryLoader
();
Class
dictLoader
;
// TODO log dictionary loader used
// If a specific dictionary path was specified, force to use that
final
String
path
=
settings
.
get
(
"hebrew.dict.path"
);
if
(
path
!=
null
&&
!
path
.
isEmpty
())
{
DictReceiver
.
setDictionary
(
path
);
}
else
if
(
DictReceiver
.
getDictionary
()
==
null
)
{
DictReceiver
.
setDictionary
(
loader
,
path
);
}
else
{
// Default to loading from default locations
DictReceiver
.
setDictionary
(
loader
);
}
if
(
DictReceiver
.
getDictionary
()
==
null
)
{
throw
new
IllegalArgumentException
(
"Could not load any dictionary. Aborting!"
);
}
}
@Override
public
String
name
()
{
return
"elasticsearch-analysis-hebrew"
;
...
...
src/main/java/com/code972/elasticsearch/plugins/DictReceiver.java
View file @
2ede8de8
package
com.code972.elasticsearch.plugins
;
import
com.code972.hebmorph.DictionaryLoader
;
import
com.code972.hebmorph.datastructures.DictHebMorph
;
import
com.code972.hebmorph.hspell.HSpellDictionaryLoader
;
import
org.elasticsearch.SpecialPermission
;
import
java.io.File
;
...
...
@@ -14,25 +14,20 @@ import java.security.PrivilegedAction;
* to initialize loading them and initializing the HebMorph analyzers.
*/
public
class
DictReceiver
{
private
static
String
[]
filePaths
=
{
"plugins/analysis-hebrew/dictionary.dict"
,
"/var/lib/hebmorph/dictionary.dict"
,
"plugins/analysis-hebrew/hspell-data-files/"
,
"/var/lib/hspell-data-files/"
};
private
static
DictHebMorph
dict
=
null
;
public
static
DictHebMorph
getDictionary
()
{
if
(
dict
==
null
)
{
dict
=
setDefaultDictionary
();
}
return
dict
;
}
private
static
class
LoadDictAction
implements
PrivilegedAction
<
DictHebMorph
>
{
private
final
String
path
;
private
final
HSpell
DictionaryLoader
loader
;
private
final
DictionaryLoader
loader
;
public
LoadDictAction
(
final
String
path
)
{
public
LoadDictAction
(
final
String
path
,
final
DictionaryLoader
loader
)
{
this
.
path
=
path
;
this
.
loader
=
new
HSpellDictionaryL
oader
()
;
this
.
loader
=
l
oader
;
}
@Override
...
...
@@ -42,6 +37,7 @@ public class DictReceiver {
try
{
return
loader
.
loadDictionaryFromPath
(
path
);
}
catch
(
IOException
e
)
{
// TODO remove printing
e
.
printStackTrace
();
}
}
...
...
@@ -49,7 +45,7 @@ public class DictReceiver {
}
}
public
static
boolean
setDictionary
(
String
path
)
{
public
static
boolean
setDictionary
(
DictionaryLoader
loader
,
String
path
)
{
SecurityManager
sm
=
System
.
getSecurityManager
();
if
(
sm
!=
null
)
{
// unprivileged code such as scripts do not have SpecialPermission
...
...
@@ -57,24 +53,25 @@ public class DictReceiver {
}
if
(
path
!=
null
)
{
final
DictHebMorph
tmp
=
AccessController
.
doPrivileged
(
new
LoadDictAction
(
path
));
final
DictHebMorph
tmp
=
AccessController
.
doPrivileged
(
new
LoadDictAction
(
path
,
loader
));
if
(
dict
!=
null
)
{
dict
=
tmp
;
return
true
;
}
}
return
false
;
}
p
rivate
static
DictHebMorph
setD
efaultD
ictionary
()
{
p
ublic
static
DictHebMorph
setDictionary
(
DictionaryLoader
loader
)
{
SecurityManager
sm
=
System
.
getSecurityManager
();
if
(
sm
!=
null
)
{
// unprivileged code such as scripts do not have SpecialPermission
sm
.
checkPermission
(
new
SpecialPermission
());
}
for
(
final
String
path
:
fi
lePaths
)
{
final
DictHebMorph
dict
=
AccessController
.
doPrivileged
(
new
LoadDictAction
(
path
));
for
(
final
String
path
:
loader
.
dictionaryPossib
lePaths
()
)
{
final
DictHebMorph
dict
=
AccessController
.
doPrivileged
(
new
LoadDictAction
(
path
,
loader
));
if
(
dict
!=
null
)
return
dict
;
}
...
...
src/main/java/com/code972/elasticsearch/plugins/HebMorphAnalysisModule.java
0 → 100644
View file @
2ede8de8
package
com.code972.elasticsearch.plugins
;
import
com.code972.hebmorph.DictionaryLoader
;
import
com.code972.hebmorph.hspell.HSpellDictionaryLoader
;
import
org.elasticsearch.common.inject.AbstractModule
;
import
org.elasticsearch.common.logging.ESLogger
;
import
org.elasticsearch.common.logging.Loggers
;
public
class
HebMorphAnalysisModule
extends
AbstractModule
{
protected
final
ESLogger
log
=
Loggers
.
getLogger
(
this
.
getClass
());
@Override
protected
void
configure
()
{
try
{
Class
hebMorphDictLoader
;
if
((
hebMorphDictLoader
=
Class
.
forName
(
"com.code972.hebmorph.HebMorphDictionaryLoader"
))
!=
null
)
{
bind
(
DictionaryLoader
.
class
).
to
(
hebMorphDictLoader
).
asEagerSingleton
();
log
.
info
(
"Auditlog available ({})"
,
hebMorphDictLoader
.
getSimpleName
());
}
else
{
throw
new
ClassNotFoundException
();
}
}
catch
(
ClassNotFoundException
e
)
{
bind
(
DictionaryLoader
.
class
).
to
(
HSpellDictionaryLoader
.
class
).
asEagerSingleton
();
log
.
info
(
"Using hspell dictionary loader"
);
}
}
}
src/test/java/com/code972/elasticsearch/plugins/TestDictionaryLoaderDetection.java
0 → 100644
View file @
2ede8de8
package
com.code972.elasticsearch.plugins
;
/**
* Created by synhershko on 06/11/2016.
*/
public
class
TestDictionaryLoaderDetection
{
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment