Commit c11fb1cf authored by Matija Obreza's avatar Matija Obreza

ElasticSearch

parent f2f4e14a
......@@ -337,6 +337,12 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>4.5.1.Final</version>
<exclusions>
<exclusion>
<artifactId>solr-analysis-extras</artifactId>
<groupId>org.apache.solr</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
......@@ -419,6 +425,66 @@
<version>${jetty.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>1.0.2.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>lucene-core</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-sandbox</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-queries</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-codecs</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-grouping</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-memory</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-spatial</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-suggest</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-queryparser</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-misc</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-join</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-highlighter</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-analyzers-common</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
......
package org.apache.lucene.util;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.util.Locale;
/**
* Use by certain classes to match version compatibility across releases of
* Lucene.
*
* <p>
* <b>WARNING</b>: When changing the version parameter that you supply to
* components in Lucene, do not simply change the version at search-time, but
* instead also adjust your indexing code to match, and re-index.
*/
public enum Version {
/**
* Match settings and bugs in Lucene's 2.0 release.
*
* @deprecated (3.1) Use latest
*/
@Deprecated
LUCENE_20,
/**
* Match settings and bugs in Lucene's 2.1 release.
*
* @deprecated (3.1) Use latest
*/
@Deprecated
LUCENE_21,
/**
* Match settings and bugs in Lucene's 2.2 release.
*
* @deprecated (3.1) Use latest
*/
@Deprecated
LUCENE_22,
/**
* Match settings and bugs in Lucene's 2.3 release.
*
* @deprecated (3.1) Use latest
*/
@Deprecated
LUCENE_23,
/**
* Match settings and bugs in Lucene's 2.4 release.
*
* @deprecated (3.1) Use latest
*/
@Deprecated
LUCENE_24,
/**
* Match settings and bugs in Lucene's 2.9 release.
*
* @deprecated (3.1) Use latest
*/
@Deprecated
LUCENE_29,
/**
* Match settings and bugs in Lucene's 3.0 release.
*
* @deprecated (4.0) Use latest
*/
@Deprecated
LUCENE_30,
/**
* Match settings and bugs in Lucene's 3.1 release.
*
* @deprecated (4.0) Use latest
*/
@Deprecated
LUCENE_31,
/**
* Match settings and bugs in Lucene's 3.2 release.
*
* @deprecated (4.0) Use latest
*/
@Deprecated
LUCENE_32,
/**
* Match settings and bugs in Lucene's 3.3 release.
*
* @deprecated (4.0) Use latest
*/
@Deprecated
LUCENE_33,
/**
* Match settings and bugs in Lucene's 3.4 release.
*
* @deprecated (4.0) Use latest
*/
@Deprecated
LUCENE_34,
/**
* Match settings and bugs in Lucene's 3.5 release.
*
* @deprecated (4.0) Use latest
*/
@Deprecated
LUCENE_35,
/**
* Match settings and bugs in Lucene's 3.6 release.
*
* @deprecated (4.0) Use latest
*/
@Deprecated
LUCENE_36,
/**
* Match settings and bugs in Lucene's 3.6 release.
*
* @deprecated (4.1) Use latest
*/
@Deprecated
LUCENE_40,
/**
* Match settings and bugs in Lucene's 4.1 release.
*
* @deprecated (4.2) Use latest
*/
@Deprecated
LUCENE_41,
/**
* Match settings and bugs in Lucene's 4.2 release.
*
* @deprecated (4.3) Use latest
*/
@Deprecated
LUCENE_42,
/**
* Match settings and bugs in Lucene's 4.3 release.
*
* @deprecated (4.4) Use latest
*/
@Deprecated
LUCENE_43,
/**
* Match settings and bugs in Lucene's 4.4 release.
*
* @deprecated (4.5) Use latest
*/
@Deprecated
LUCENE_44,
/**
* Match settings and bugs in Lucene's 4.5 release.
*
* @deprecated (4.6) Use latest
*/
@Deprecated
LUCENE_45,
/**
* Match settings and bugs in Lucene's 4.6 release.
*
* @deprecated (4.7) Use latest
*/
@Deprecated
LUCENE_46,
/**
* Match settings and bugs in Lucene's 4.7 release.
*
* @deprecated (4.8) Use latest
*/
@Deprecated
LUCENE_47,
/**
* Match settings and bugs in Lucene's 4.8 release.
* <p>
* Use this to get the latest &amp; greatest settings, bug fixes, etc, for
* Lucene.
*/
LUCENE_48,
/* Add new constants for later versions **here** to respect order! */
/**
* <p>
* <b>WARNING</b>: if you use this setting, and then upgrade to a newer
* release of Lucene, sizable changes may happen. If backwards compatibility
* is important then you should instead explicitly specify an actual
* version.
* <p>
* If you use this constant then you may need to <b>re-index all of your
* documents</b> when upgrading Lucene, as the way text is indexed may have
* changed. Additionally, you may need to <b>re-test your entire
* application</b> to ensure it behaves as expected, as some defaults may
* have changed and may break functionality in your application.
*
* @deprecated Use an actual version instead.
*/
@Deprecated
LUCENE_CURRENT;
public boolean onOrAfter(Version other) {
return compareTo(other) >= 0;
}
public static Version parseLeniently(String version) {
String parsedMatchVersion = version.toUpperCase(Locale.ROOT);
return Version.valueOf(parsedMatchVersion.replaceFirst("^(\\d)\\.(\\d)$", "LUCENE_$1$2"));
}
}
package org.genesys2.server.model.elastic;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import org.genesys2.server.model.genesys.ExperimentTrait;
import org.genesys2.server.model.genesys.Method;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Parent;
@Document(indexName = "genesys", type = "trait", refreshInterval = "-1")
public class AccessionEsTrait {
private static final Logger LOG = Logger.getLogger(AccessionDetails.class);
@Id
private Long id;
@Version
private Long version;
@Parent(type = "mcpd")
private long accessionId;
@Field(index = FieldIndex.not_analyzed, type = FieldType.Long)
private long methodId;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private Set<String> sval = new HashSet<String>();
@Field(index = FieldIndex.not_analyzed, type = FieldType.Long)
private Set<Long> ival = new HashSet<Long>();
@Field(index = FieldIndex.not_analyzed, type = FieldType.Double)
private Set<Double> dval = new HashSet<Double>();
public static List<AccessionEsTrait> traits(List<Method> listMethods, Map<Long, List<ExperimentTrait>> accessionTraitValues) {
ArrayList<AccessionEsTrait> accessionEsTraits = new ArrayList<AccessionEsTrait>();
if (listMethods == null || listMethods.isEmpty())
return accessionEsTraits;
if (accessionTraitValues == null || accessionTraitValues.isEmpty())
return accessionEsTraits;
for (Method m : listMethods) {
List<ExperimentTrait> vals = accessionTraitValues.get(m.getId());
if (vals != null && !vals.isEmpty())
accessionEsTraits.add(AccessionEsTrait.from(m, vals));
}
return accessionEsTraits;
}
public static AccessionEsTrait from(Method m, List<ExperimentTrait> vals) {
AccessionEsTrait t = new AccessionEsTrait();
t.methodId = m.getId();
t.sval = new HashSet<String>();
for (ExperimentTrait et : vals) {
Object value = et.getValue();
if (et == null || value == null)
continue;
if (value instanceof String)
t.sval.add((String) value);
else if (value instanceof Integer)
t.ival.add(((Integer) value).longValue());
else if (value instanceof Long)
t.ival.add((Long) value);
else if (value instanceof Double)
t.dval.add((Double) value);
else if (value instanceof Float)
t.dval.add(((Float) value).doubleValue());
else if (value instanceof BigDecimal)
t.dval.add(((BigDecimal) value).doubleValue());
else
LOG.warn("Unsupported value type " + value.getClass());
}
return t;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
public long getAccessionId() {
return accessionId;
}
public void setAccessionId(long accessionId) {
this.accessionId = accessionId;
}
public long getMethodId() {
return methodId;
}
public void setMethodId(long methodId) {
this.methodId = methodId;
}
public Set<String> getSval() {
return sval;
}
public void setSval(Set<String> sval) {
this.sval = sval;
}
public Set<Long> getIval() {
return ival;
}
public void setIval(Set<Long> ival) {
this.ival = ival;
}
public Set<Double> getDval() {
return dval;
}
public void setDval(Set<Double> dval) {
this.dval = dval;
}
}
\ No newline at end of file
package org.genesys2.server.model.elastic;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.model.genesys.AccessionAlias;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
public class Alias {
private String name;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String lang;
private String usedBy;
public static Alias from(AccessionAlias aa) {
Alias a = new Alias();
a.name = aa.getName();
a.lang = StringUtils.defaultIfBlank(aa.getLang(), null);
a.usedBy = StringUtils.defaultIfBlank(aa.getUsedBy(), null);
return a;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLang() {
return lang;
}
public void setLang(String lang) {
this.lang = lang;
}
public String getUsedBy() {
return usedBy;
}
public void setUsedBy(String usedBy) {
this.usedBy = usedBy;
}
}
\ No newline at end of file
package org.genesys2.server.model.elastic;
import java.util.Date;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
public class Collect {
public String collCode;
@Field(searchAnalyzer = "keyword", type = FieldType.String)
public String collDate;
public String collInstAddr;
public String collMissId;
public String collName;
@Field(searchAnalyzer = "keyword", type = FieldType.String)
public String collNumb;
public String collSite;
public Integer collSrc;
public Date collectingDate;
public static Collect from(AccessionCollect collect) {
if (collect == null)
return null;
Collect c = new Collect();
c.collCode = StringUtils.defaultIfBlank(collect.getCollCode(), null);
c.collDate = StringUtils.defaultIfBlank(collect.getCollDate(), null);
c.collInstAddr = StringUtils.defaultIfBlank(collect.getCollInstAddress(), null);
c.collMissId = StringUtils.defaultIfBlank(collect.getCollMissId(), null);
c.collName = StringUtils.defaultIfBlank(collect.getCollName(), null);
c.collNumb = StringUtils.defaultIfBlank(collect.getCollNumb(), null);
c.collSite = StringUtils.defaultIfBlank(collect.getCollSite(), null);
c.collSrc = collect.getCollSrc();
return c;
}
}
\ No newline at end of file
package org.genesys2.server.model.elastic;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
public class Country {
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String iso3;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String iso2;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String name;
public static Country from(org.genesys2.server.model.impl.Country country) {
Country c = new Country();
if (country != null) {
c.iso3 = country.getCode3();
c.iso2 = country.getCode2();
c.name = country.getName();
}
return c;
}
public String getIso3() {
return iso3;
}
public void setIso3(String iso3) {
this.iso3 = iso3;
}
public String getIso2() {
return iso2;
}
public void setIso2(String iso2) {
this.iso2 = iso2;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
\ No newline at end of file
package org.genesys2.server.model.elastic;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.model.genesys.AccessionGeo;
public class Geo {
private String method;
private Double uncertainty;
private Double latitude;
private Double longitude;
private Double[] coordinates;
private Double elevation;
private String datum;
public static Geo from(AccessionGeo ag) {