Commit ef2fbb13 authored by Matija Obreza's avatar Matija Obreza
Browse files

Explorer: autocomplete genus, taxonomy; added inTrust filtering

parent 1b11596b
......@@ -19,7 +19,9 @@ package org.genesys2.server.persistence.domain;
import java.util.List;
import org.genesys2.server.model.genesys.Taxonomy;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface TaxonomyRepository extends JpaRepository<Taxonomy, Long> {
Taxonomy getByGenusAndSpecies(String genus, String species);
......@@ -27,4 +29,10 @@ public interface TaxonomyRepository extends JpaRepository<Taxonomy, Long> {
List<Taxonomy> findByGenus(String genus);
Taxonomy getByTaxonName(String fullTaxa);
@Query("select distinct t.genus from Taxonomy t where t.genus like ?1")
List<String> autocompleteGenus(String term, Pageable page);
@Query("select distinct t.taxonName from Taxonomy t where t.taxonName like ?1")
List<String> autocompleteTaxonomy(String term, Pageable page);
}
......@@ -28,12 +28,14 @@ import com.fasterxml.jackson.databind.JsonNode;
public interface GenesysFilterService {
String[] DEFAULT_FILTERS = { "crop", "genus", "taxon", "origin", "lat", "lon", "organization", "institute", "accenumb", "inSvalbard", "mls", "inTrust", "available" };
Page<Accession> listAccessions(JsonNode jsonTree, Pageable pageable);
List<GenesysFilter> listAvailableFilters();
public static interface GenesysFilter {
public String getKey();
public enum DataType {
......
......@@ -16,6 +16,8 @@
package org.genesys2.server.service;
import java.util.List;
import org.genesys2.server.model.genesys.Taxonomy;
public interface TaxonomyService {
......@@ -25,4 +27,8 @@ public interface TaxonomyService {
Taxonomy ensureTaxonomy(String genus, String species); // , String
// fullTaxa);
List<String> autocompleteGenus(String term);
List<String> autocompleteTaxonomy(String term);
}
......@@ -45,6 +45,7 @@ import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysFilterService.GenesysFilter.DataType;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.SearchService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.TraitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
......@@ -90,6 +91,9 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
@Autowired
private SearchService searchService;
@Autowired
private TaxonomyService taxonomyService;
@Autowired
public void setDataSource(final DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
......@@ -97,10 +101,10 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
public GenesysFilterServiceImpl() {
this.availableFilters = new ArrayList<GenesysFilter>();
// "origin", "institute", "lat", "lon", "alt", "genus"
this.availableFilters.add(new GenesysFilterImpl("crop", DataType.STRING));
this.availableFilters.add(new GenesysFilterImpl("genus", DataType.STRING));
this.availableFilters.add(new GenesysFilterImpl("taxon", DataType.STRING));
this.availableFilters.add(new GenesysAutocompleteFilterImpl("genus", "/explore/ac/genus"));
this.availableFilters.add(new GenesysAutocompleteFilterImpl("taxon", "/explore/ac/taxonomy"));
this.availableFilters.add(new GenesysAutocompleteFilterImpl("origin", "/explore/ac/country"));
this.availableFilters.add(new GenesysFilterImpl("lat", DataType.NUMERIC));
......@@ -112,6 +116,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
this.availableFilters.add(new GenesysFilterImpl("accenumb", DataType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl("inSvalbard", DataType.BOOLEAN));
this.availableFilters.add(new GenesysFilterImpl("mls", DataType.BOOLEAN));
this.availableFilters.add(new GenesysFilterImpl("inTrust", DataType.BOOLEAN));
this.availableFilters.add(new GenesysFilterImpl("available", DataType.BOOLEAN));
}
......@@ -219,6 +224,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
createQuery(sbf, "a.instCode", jsonTree.get("institute"), params);
createQuery(sbf, "a.inSGSV", jsonTree.get("inSvalbard"), params);
createQuery(sbf, "a.mlsStat", jsonTree.get("mls"), params);
createQuery(sbf, "a.inTrust", jsonTree.get("inTrust"), params);
createQuery(sbf, "a.available", jsonTree.get("available"), params);
createQuery(sbf, "org.slug", jsonTree.get("organization"), params);
createQuery(sbf, "t.genus", jsonTree.get("genus"), params);
......@@ -469,15 +475,27 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
public List<LabelValue<String>> autocomplete(String filter, String ac) {
List<LabelValue<String>> completed = new ArrayList<LabelValue<String>>();
if ("instCode".equalsIgnoreCase(filter)) {
List<FaoInstitute> faoInst = searchService.autocomplete(ac + "*", FaoInstitute.class);
List<FaoInstitute> faoInst = searchService.autocomplete(ac, FaoInstitute.class);
for (FaoInstitute inst : faoInst) {
completed.add(new LabelValue<String>(inst.getCode(), inst.getCode() + ", " + inst.getFullName()));
}
} else if ("country".equalsIgnoreCase(filter)) {
List<Country> countries = searchService.autocomplete(ac + "*", Country.class);
List<Country> countries = searchService.autocomplete(ac, Country.class);
for (Country c : countries) {
completed.add(new LabelValue<String>(c.getCode3(), c.getCode3() + ", " + c.getName()));
}
} else if ("genus".equalsIgnoreCase(filter)) {
List<String> genera = taxonomyService.autocompleteGenus(ac);
for (String genus : genera) {
completed.add(new LabelValue<String>(genus, genus));
}
} else if ("taxonomy".equalsIgnoreCase(filter)) {
List<String> taxa = taxonomyService.autocompleteTaxonomy(ac);
for (String taxonomy : taxa) {
completed.add(new LabelValue<String>(taxonomy, taxonomy));
}
} else {
throw new RuntimeException("No autocompleter for " + filter);
}
return completed;
}
......
......@@ -106,7 +106,7 @@ public class SearchServiceImpl implements SearchService {
org.apache.lucene.search.Query luceneQuery = null;
try {
luceneQuery = getLuceneQuery(searchQuery, new String[] { "body" });
luceneQuery = getLuceneQuery(searchQuery + "*", new String[] { "body" });
org.hibernate.search.jpa.FullTextQuery query = ftEm.createFullTextQuery(luceneQuery, clazz);
return (List<T>) query.setMaxResults(10).setFirstResult(0).getResultList();
......
......@@ -16,6 +16,8 @@
package org.genesys2.server.service.impl;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
......@@ -23,6 +25,7 @@ import org.genesys2.server.model.genesys.Taxonomy;
import org.genesys2.server.persistence.domain.TaxonomyRepository;
import org.genesys2.server.service.TaxonomyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -73,4 +76,13 @@ public class TaxonomyServiceImpl implements TaxonomyService {
return taxonomy;
}
@Override
public List<String> autocompleteGenus(String term) {
return taxonomyRepository.autocompleteGenus(term + "%", new PageRequest(0, 10));
}
@Override
public List<String> autocompleteTaxonomy(String term) {
return taxonomyRepository.autocompleteTaxonomy("%" + term + "%", new PageRequest(0, 10));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment