Changeset 6694


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

highlighting and wildcards:

  • strip them when matching
  • use word only matching unless they are present
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

    r6691 r6694  
    2727public class HighlightSearchTermScriptFactory implements Serializable {
    2828
    29     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})";
    3030
    31     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";
    3234
    3335    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) {
    3440        return String.format(HIGHLIGHT_FUNCTION,
    3541                componentSelector,
    3642                makeWordListArray(words),
    37                 getSearchWordClass()
     43                cssClass,
     44                matchWordsOnly(words)
    3845        );
     46    }
     47
     48    protected boolean matchWordsOnly(String query) {
     49        // string with asterixes or question marks should match by character
     50        return !query.matches(".*[\\*\\?].*");
    3951    }
    4052
     
    7890                //or boosting values
    7991                + "|['\"]?\\^.*"
    80                 + ")$",
     92                + ")$"
     93                //also remove wildcard characters
     94                + "|[\\?\\*]",
    8195                //replace with empty string
    8296                "");
    83     }
    84 
    85     /**
    86      *
    87      * @return CSS class to mark matches with
    88      */
    89     protected String getSearchWordClass() {
    90         return "searchword";
    9197    }
    9298
Note: See TracChangeset for help on using the changeset viewer.