Changeset 6695


Ignore:
Timestamp:
10/21/15 14:13:00 (9 years ago)
Author:
Twan Goosen
Message:

merged changes from 3.3 branch to trunk

Location:
vlo/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • vlo/trunk

  • vlo/trunk/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/HighlightSearchTermScriptFactory.java

    r6690 r6695  
    1818
    1919import com.google.common.collect.ImmutableSet;
     20import java.io.Serializable;
    2021import java.util.Collection;
    2122
     
    2425 * @author Twan Goosen <twan.goosen@mpi.nl>
    2526 */
    26 public class HighlightSearchTermScriptFactory {
     27public class HighlightSearchTermScriptFactory implements Serializable {
    2728
    28     private static final String HIGHLIGHT_FUNCTION = "$('%s').highlight(%s, {className:'%s'})";
     29    public static final String HIGHLIGHT_FUNCTION = "$('%s').highlight(%s, {className:'%s', wordsOnly: %s})";
    2930
    30     private static final Collection<String> DEFAULT_EXCLUDE_WORDS = ImmutableSet.of("and", "or", "not", "to");
     31    public static final Collection<String> DEFAULT_EXCLUDE_WORDS = ImmutableSet.of("and", "or", "not", "to");
     32
     33    public static final String DEFAULT_CSS_CLASS = "searchword";
    3134
    3235    public String createScript(String componentSelector, final String words) {
     36        return createScript(componentSelector, words, DEFAULT_CSS_CLASS);
     37    }
     38
     39    public String createScript(String componentSelector, final String words, String cssClass) {
    3340        return String.format(HIGHLIGHT_FUNCTION,
    3441                componentSelector,
    3542                makeWordListArray(words),
    36                 getSearchWordClass()
     43                cssClass,
     44                matchWordsOnly(words)
    3745        );
     46    }
     47
     48    protected boolean matchWordsOnly(String query) {
     49        // string with asterixes or question marks should match by character
     50        return !query.matches(".*[\\*\\?].*");
    3851    }
    3952
     
    7790                //or boosting values
    7891                + "|['\"]?\\^.*"
    79                 + ")$",
     92                + ")$"
     93                //also remove wildcard characters
     94                + "|[\\?\\*]",
    8095                //replace with empty string
    8196                "");
    82     }
    83 
    84     /**
    85      *
    86      * @return CSS class to mark matches with
    87      */
    88     protected String getSearchWordClass() {
    89         return "searchword";
    9097    }
    9198
Note: See TracChangeset for help on using the changeset viewer.