From 2f11b2dbfa33a45de9b86c8218fb23fa1f865ed7 Mon Sep 17 00:00:00 2001 From: "valia.tsagkalidou" Date: Tue, 14 Oct 2008 15:15:32 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerCore@4717 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../framework/core/util/FindInfo.java | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/org/gcube/application/framework/core/util/FindInfo.java b/src/org/gcube/application/framework/core/util/FindInfo.java index 2bab508..f955c20 100644 --- a/src/org/gcube/application/framework/core/util/FindInfo.java +++ b/src/org/gcube/application/framework/core/util/FindInfo.java @@ -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 searchCollectionInfo(String term, String whereToSearch, List[] 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; + } } } }