Changeset 6689


Ignore:
Timestamp:
10/20/15 13:15:51 (9 years ago)
Author:
Twan Goosen
Message:

improved query sanitising for highlighting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.3/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/HighlightSearchTermScriptFactory.java

    r6687 r6689  
    1919import com.google.common.collect.ImmutableSet;
    2020import java.util.Collection;
    21 import org.apache.wicket.util.string.StringValue;
    2221
    2322/**
     
    3332    public String createScript(String componentSelector, final String words) {
    3433        return String.format(HIGHLIGHT_FUNCTION,
    35                 componentSelector, 
     34                componentSelector,
    3635                makeWordListArray(words),
    3736                getSearchWordClass()
     
    6362
    6463    private String sanitise(String word) {
    65         return word.replaceAll("^[\\s'\"]+|[\\s'\"]+$", "");
     64        //remove everything up to first colon and strip off quotation marks and white space
     65        return word.replaceAll(
     66                //match beginning
     67                "^("
     68                //case with colon (also strip quotes + optional whitespace after quotes)
     69                + "[^:\"']+:(['\"])?"
     70                //or case without colon (strip quotes and white space)
     71                + "|['\"]+"
     72                + ")"
     73                //match end
     74                + "|("
     75                //quotes
     76                + "['\"]+"
     77                //or boosting values
     78                + "|['\"]?\\^.*"
     79                + ")$",
     80                //replace with empty string
     81                "");
    6682    }
    6783
Note: See TracChangeset for help on using the changeset viewer.