git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerCore@4717 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d9b880b3ea
commit
2f11b2dbfa
|
@ -3,6 +3,8 @@ package org.gcube.application.framework.core.util;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.gcube.application.framework.core.commons.model.CollectionInfo;
|
||||
import org.gcube.application.framework.core.commons.model.SearchField;
|
||||
|
@ -53,6 +55,27 @@ public class FindInfo {
|
|||
|
||||
public static List<CollectionInfo> searchCollectionInfo(String term, String whereToSearch, List<CollectionInfo>[] collections)
|
||||
{
|
||||
term = term.trim().toLowerCase();
|
||||
if(term.startsWith("*"))
|
||||
{
|
||||
term = term.substring(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
term = "(\\s|\\p{Punct})" + term;
|
||||
}
|
||||
if(term.endsWith("*"))
|
||||
{
|
||||
term = term.substring(0,term.length()-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
term = term + "(\\s|\\p{Punct})";
|
||||
}
|
||||
term = term.replaceAll("\\x2A", ".*");
|
||||
term = term.replaceAll("\\x3F", ".");
|
||||
Pattern pattern = Pattern.compile(term);
|
||||
|
||||
boolean name = false, descr = false;
|
||||
if(whereToSearch.equals(FindInfo.ALL))
|
||||
{
|
||||
|
@ -72,15 +95,21 @@ public class FindInfo {
|
|||
{
|
||||
for(int c2=0; c2 < collections[counter].size(); c2++)
|
||||
{
|
||||
if(name && collections[counter].get(c2).getName().toLowerCase().contains(term.toLowerCase()))
|
||||
if(name)
|
||||
{
|
||||
res.add(collections[counter].get(c2));
|
||||
continue;
|
||||
if(pattern.matcher(" " + collections[counter].get(c2).getName().toLowerCase() + " ").find())
|
||||
{
|
||||
res.add(collections[counter].get(c2));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(descr && collections[counter].get(c2).getDescription().toLowerCase().contains(term.toLowerCase()))
|
||||
if(descr)
|
||||
{
|
||||
res.add(collections[counter].get(c2));
|
||||
continue;
|
||||
if(pattern.matcher(" " + collections[counter].get(c2).getDescription().toLowerCase() + " ").find())
|
||||
{
|
||||
res.add(collections[counter].get(c2));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue