valia.tsagkalidou 2008-10-14 15:15:32 +00:00
parent d9b880b3ea
commit 2f11b2dbfa
1 changed files with 35 additions and 6 deletions

View File

@ -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;
}
}
}
}