- search by text query
- help file

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/speciesdiscovery@79178 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2013-07-15 15:44:36 +00:00
parent 861ac1fbbb
commit 5b03a78acb
8 changed files with 182 additions and 9 deletions

View File

@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import org.gcube.portlets.user.gcubegisviewer.client.GCubeGisViewer;
@ -89,6 +90,7 @@ import org.gcube.portlets.user.speciesdiscovery.shared.SearchType;
import org.gcube.portlets.user.speciesdiscovery.shared.SpeciesCapability;
import org.gcube.portlets.user.speciesdiscovery.shared.TaxonomyRow;
import org.gcube.portlets.user.speciesdiscovery.shared.filter.ResultFilter;
import org.gcube.portlets.user.speciesdiscovery.shared.util.SearchTermValidator;
import org.gcube.portlets.user.workspace.lighttree.client.ItemType;
import org.gcube.portlets.user.workspace.lighttree.client.event.DataLoadEvent;
import org.gcube.portlets.user.workspace.lighttree.client.event.DataLoadHandler;
@ -1300,6 +1302,23 @@ public class SearchController {
lastSearchEvent.setResultType(capability);
lastSearchEvent.setMapTermsSearched(queryParameters.getTerms());
System.out.println("queryParameters.getTerms() "+queryParameters.getTerms());
if(queryParameters.getTerms()!=null){
String terms = "";
for (SearchType key : queryParameters.getTerms().keySet()) {
terms += queryParameters.getTerms().get(key)+",";
}
if(terms.length()>2){
terms = terms.substring(0, terms.length()-1);
}
terms = terms.replaceAll("\\[", "").replaceAll("\\]",""); //REMOVE brackets
lastSearchEvent.setSearchTerm(terms);
}
setDataSourceType(capability);
switchView(capability);
@ -1326,6 +1345,10 @@ public class SearchController {
AsyncCallback<SearchByQueryParameter> callback = initSearchByQueryCallback();
//VALIDATOR
query = SearchTermValidator.replaceOccurrenceTermWithProduct(query);
SpeciesDiscovery.taxonomySearchService.searchByQuery(query, callback);
eventBus.fireEvent(new SearchStartedEvent());
@ -1347,6 +1370,10 @@ public class SearchController {
Log.trace("**********result type: " + filters.getResultType());
//VALIDATOR
searchTerm = SearchTermValidator.validateQueryTerm(searchTerm);
switch (type) {
case BY_SCIENTIFIC_NAME:

View File

@ -52,7 +52,7 @@ import com.google.gwt.user.client.ui.Button;
*
*/
public class SpeciesSearchFormPanel extends ContentPanel {
protected static final String SEARCH = "Search";
protected static final String EXSEARCH = "ex. sarda sarda, solea solea";
protected Button buttSimpleSearch;
protected Button buttSimpleExample;
protected SimpleComboBox<String> searchType;
@ -220,7 +220,7 @@ public class SpeciesSearchFormPanel extends ContentPanel {
private void initQuerySearchPanel() {
querySeachPanel.setSpacing(5);
buttQuerySearch = new Button(SEARCH);
buttQuerySearch = new Button("Search");
buttQuerySearch.setStyleName("wizardButton");
@ -281,7 +281,7 @@ public class SpeciesSearchFormPanel extends ContentPanel {
searchField = new TextField<String>();
searchField.setStyleAttribute("margin-left", "10px");
searchField.setStyleAttribute("margin-right", "10px");
searchField.setEmptyText(SEARCH);
searchField.setEmptyText(EXSEARCH);
searchField.setWidth(300);
searchField.addKeyListener(new KeyListener(){
@ -301,7 +301,7 @@ public class SpeciesSearchFormPanel extends ContentPanel {
// simpleSearchPanel.add(checkValidateOccurrences);
buttSimpleSearch = new Button(SEARCH);
buttSimpleSearch = new Button("Search");
buttSimpleSearch.addClickHandler(new ClickHandler() {

View File

@ -2,7 +2,7 @@
<h3><span class="info-title">Examples</span></h3>
<p class="info-query-description">Search all the products about the scientific name 'sarda sarda' in all available datasources.</p>
<p class="info-query-text">SEARCH BY SN 'sarda sarda'</p>
<p class="info-query-text">SEARCH BY SN 'sarda sarda' RETURN Product</p>
<p class="info-query-description">Search all the products about 'sarda sarda' and his synonyms in WoRMS, in all available datasources.</p>
<p class="info-query-text">SEARCH BY SN 'sarda sarda' EXPAND WITH WoRMS</p>
@ -29,7 +29,7 @@
<pre>SEARCH BY <i><b>term</b></i> [, ...]
[ IN <i><b>datasource</b></i> [, ...] ]
[ WHERE <i><b>condition</b></i> [AND <i><b>condition</b></i>] ]
[ RETURN {PRODUCT | OCCURRENCE | TAXON} ]
[ RETURN {OCCURRENCE | TAXON} ]
[ HAVING <i><b>having expression</b></i> ]
</pre></code>
<p class="info-padding"></p>

View File

@ -37,6 +37,14 @@ public class CommonDetailComponents {
private String getSearchType(){
String searchType = "";
if(lastSearchEvent.getMapTermsSearched()!=null){
searchType = lastSearchEvent.getMapTermsSearched().toString();
}
else{
switch (lastSearchEvent.getType()) {
case BY_COMMON_NAME:
@ -50,6 +58,7 @@ public class CommonDetailComponents {
break;
}
}
return searchType;
}

View File

@ -32,6 +32,7 @@ public class QueryUtil {
Query query = SPQLQueryParser.parse(queryText);
Map<SearchType, List<String>> terms = new HashMap<SearchType, List<String>>();
for (Term term:query.getTerms()) {
switch (term.getType()) {
case COMMON_NAME: terms.put(SearchType.BY_COMMON_NAME, term.getWords()); break;
@ -39,6 +40,8 @@ public class QueryUtil {
}
}
logger.trace("found terms: "+terms);
ReturnType returnType = query.getReturnType();
SearchResultType searchResultType = SearchResultType.SPECIES_PRODUCT;
@ -48,6 +51,8 @@ public class QueryUtil {
case TAXON: searchResultType = SearchResultType.TAXONOMY_ITEM; break;
}
logger.trace("found returnType: "+searchResultType);
return new SearchByQueryParameter(terms, searchResultType);
} catch (Exception e) {

View File

@ -47,6 +47,16 @@ public class SearchByQueryParameter implements Serializable{
this.terms = terms;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("SearchByQueryParameter [searchResultType=");
builder.append(searchResultType);
builder.append(", terms=");
builder.append(terms);
builder.append("]");
return builder.toString();
}
}

View File

@ -11,7 +11,7 @@ public enum SpeciesCapability {
//Capabilities
RESULTITEM("RESULTITEM", "Occurrences"),
TAXONOMYITEM("TAXONOMYITEM", "Taxonomy"),
TAXONOMYITEM("TAXONOMYITEM", "Taxon"),
OCCURRENCESPOINTS("OCCURRENCESPOINTS", "OccurrencesPoints"),

View File

@ -0,0 +1,122 @@
/**
*
*/
package org.gcube.portlets.user.speciesdiscovery.shared.util;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jul 15, 2013
*
*/
public class SearchTermValidator {
/**
*
*/
public static final String PRODUCT = " Product ";
public static final String termOccurrence = "occurrence";
/**
*
* @param queryTerms
* @return the terms formatted correctly for SPQL
*/
public static String validateQueryTerm(String queryTerms){
String validQueryTerms = "";
if(queryTerms==null || queryTerms.isEmpty())
return "";
if(queryTerms.contains(",")){ //MANY TERMS
String[] terms = queryTerms.split(",");
for (String term : terms)
validQueryTerms+= validateTerm(term) +",";
// if(validQueryTerms.length()>1) //REMOVE LAST ","
// validQueryTerms = validQueryTerms.substring(0, validQueryTerms.length()-1);
//SPQL ADDS THE CHAR ' IN HEAD AND TAIL
if(validQueryTerms.length()>3) {
//REMOVE FIRST "'"
validQueryTerms = validQueryTerms.substring(1);
//REMOVE LAST "',"
validQueryTerms = validQueryTerms.substring(0, validQueryTerms.length()-2);
}
}else{
// validQueryTerms = validateTerm(queryTerms);
validQueryTerms = queryTerms;
}
return validQueryTerms;
}
public static String validateTerm(String searchTerm){
if(searchTerm==null || searchTerm.isEmpty())
return "";
searchTerm = searchTerm.trim(); //remove white space on head and tail
if(!searchTerm.startsWith("'"))
searchTerm = "'"+searchTerm;
if(!searchTerm.endsWith("'"))
searchTerm+= "'";
return searchTerm;
}
public static String replaceOccurrenceTermWithProduct(String queryTerm){
if(queryTerm==null || queryTerm.isEmpty())
return "";
queryTerm = queryTerm.trim();
String originalQuery = queryTerm;
int startOcc = queryTerm.toLowerCase().indexOf(termOccurrence);
if(startOcc>0){
int indexStart = startOcc-1;
int indexEnd = startOcc+termOccurrence.length();
// System.out.println("indexStart: "+indexStart);
// System.out.println("indexEnd: "+indexEnd);
// System.out.println("originalQuery length: "+originalQuery.length());
return originalQuery.substring(0, indexStart) +PRODUCT + originalQuery.substring(indexEnd, originalQuery.length());
}
return originalQuery;
}
public static void main(String[] args) {
String queryTerms = "solea solea', sarda, stock'";
// System.out.println(validateQueryTerm(queryTerms));
System.out.println(replaceOccurrenceTermWithProduct("SEARCH BY SN 'sarda sarda' RETURN occurr"));
}
}