Skip to content

Commit bfa41be

Browse files
litvinovgchenejac
authored andcommitted
Moved initial letter regular expression into filter configuration.
1 parent 999eac9 commit bfa41be

File tree

5 files changed

+40
-19
lines changed

5 files changed

+40
-19
lines changed

api/src/main/java/edu/cornell/mannlib/vitro/webapp/search/controller/SearchFilter.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
public class SearchFilter {
2727

28+
private static final String DEFAULT_PATTERN = "$0";
2829
private static final String FILTER = "Filter";
2930
private static final String RANGE_FILTER = "RangeFilter";
3031
private static final Log log = LogFactory.getLog(SearchFilter.class);
@@ -57,6 +58,7 @@ private enum SortOption {
5758
private boolean input = false;
5859
private Map<String, FilterValue> values = new LinkedHashMap<>();
5960
private boolean inputRegex = false;
61+
private String regexPattern = DEFAULT_PATTERN;
6062
private boolean facetsRequired;
6163
private Order valueSortDirection = Order.ASC;
6264
private String type = FILTER;
@@ -429,4 +431,12 @@ public void setSortOption(String uri) {
429431
}
430432
}
431433
}
434+
435+
public void setRegexPattern(String regexPattern) {
436+
this.regexPattern = regexPattern;
437+
}
438+
439+
public String getInputRegex() {
440+
return regexPattern.replace(DEFAULT_PATTERN, inputText);
441+
}
432442
}

api/src/main/java/edu/cornell/mannlib/vitro/webapp/search/controller/SearchFiltering.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class SearchFiltering {
5656
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
5757
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
5858
+ "SELECT ?filter_id ?filter_type ?filter_label ?value_label ?value_id ?field_name ?public ?filter_rank "
59-
+ "?value_rank (STR(?isUriReq) as ?isUri ) ?multivalued ?input ?regex ?facet ?min ?max ?role "
59+
+ "?value_rank (STR(?isUriReq) as ?isUri ) ?multivalued ?input ?regex ?regexPattern ?facet ?min ?max ?role "
6060
+ "?value_public ?more_limit ?multilingual ?isDescending\n"
6161
+ "?filterDisplayLimitRole ?valueDisplayLimitRole ?sortingObjectType \n"
6262
+ "WHERE {\n"
@@ -90,6 +90,7 @@ public class SearchFiltering {
9090
+ " OPTIONAL {?filter search:isUriValues ?isUriReq }\n"
9191
+ " OPTIONAL {?filter search:userInput ?input }\n"
9292
+ " OPTIONAL {?filter search:userInputRegex ?regex }\n"
93+
+ " OPTIONAL {?filter search:regexPattern ?regexPattern }\n"
9394
+ " OPTIONAL {?filter search:facetResults ?facet }\n"
9495
+ " OPTIONAL {?filter search:reverseFacetOrder ?isDescendingDeprecated }\n"
9596
+ " OPTIONAL {"
@@ -527,6 +528,11 @@ private static SearchFilter createSearchFilter(Map<String, SearchFilter> filters
527528
filter.setSortOption(sortOption.asResource().getURI());
528529
}
529530

531+
RDFNode regexPattern = solution.get("regexPattern");
532+
if (regexPattern != null && regexPattern.isLiteral()) {
533+
filter.setRegexPattern(regexPattern.asLiteral().getLexicalForm());
534+
}
535+
530536
RDFNode moreLimit = solution.get("more_limit");
531537
if (moreLimit != null && moreLimit.isLiteral()) {
532538
filter.setMoreLimit(moreLimit.asLiteral().getInt());
@@ -547,11 +553,10 @@ private static void addInputFilter(SearchQuery query, SearchFilter searchFilter)
547553
|| PagedSearchController.PARAM_QUERY_TEXT.equals(searchFilter.getId())) {
548554
return;
549555
}
550-
String searchText = searchFilter.getInputText();
551556
if (searchFilter.isInputRegex()) {
552-
query.addFilterQuery(searchFilter.getField() + ":/" + searchText + "/");
557+
query.addFilterQuery(searchFilter.getField() + ":/" + searchFilter.getInputRegex() + "/");
553558
} else {
554-
query.addFilterQuery(searchFilter.getField() + ":\"" + searchText + "\"");
559+
query.addFilterQuery(searchFilter.getField() + ":\"" + searchFilter.getInputText() + "\"");
555560
}
556561
}
557562

home/src/main/resources/rdf/display/firsttime/search_individuals_vitro.n3

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,22 @@
2929
a vitro-search:Filter ;
3030
rdfs:label "Label regular expression"@en-US ;
3131
vitro-search:facetResults false ;
32-
vitro-search:filterField :field_name_raw ;
33-
vitro-search:id "raw_label_regex" ;
32+
vitro-search:filterField :field_name_lowercase_single_valued ;
33+
vitro-search:id "raw_initial" ;
3434
vitro-search:public true ;
3535
vitro-search:userInput true ;
36+
vitro-search:regexPattern "$0.*" ;
3637
vitro-search:userInputRegex true .
3738

3839
:filter_label_regex
3940
a vitro-search:Filter ;
4041
rdfs:label "Label regular expression"@en-US ;
4142
vitro-search:facetResults false ;
42-
vitro-search:filterField :field_label_display ;
43-
vitro-search:id "label_regex" ;
43+
vitro-search:filterField :field_label_sort ;
44+
vitro-search:id "initial" ;
4445
vitro-search:public true ;
4546
vitro-search:userInput true ;
47+
vitro-search:regexPattern "$0.*" ;
4648
vitro-search:userInputRegex true .
4749

4850

@@ -112,6 +114,12 @@
112114
a vitro-search:SearchField ;
113115
vitro-search:indexField "nameRaw" .
114116

117+
:field_name_lowercase_single_valued
118+
a vitro-search:SearchField ;
119+
vitro-search:indexField "nameLowercaseSingleValued" .
120+
121+
122+
115123
:field_category
116124
a vitro-search:SearchField ;
117125
vitro-search:indexField "classgroup" .

home/src/main/resources/rdf/tbox/filegraph/search_ontology.n3

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ search:userInputRegex
115115
rdfs:domain search:Filter ;
116116
rdfs:range xsd:boolean .
117117

118+
search:regexPattern
119+
a owl:DatatypeProperty , owl:FunctionalProperty ;
120+
rdfs:domain search:Filter ;
121+
rdfs:range xsd:string .
122+
118123
search:sortField a owl:FunctionalProperty , owl:ObjectProperty ;
119124
rdfs:domain search:Sort ;
120125
rdfs:range search:SearchField .

webapp/src/main/webapp/templates/freemarker/body/menupage/browseSearchFilterValues.ftl

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
<#-- <#assign additionalFilters = ["type"]> -->
55
<#if filters[searchFilter]??>
66
<#if languageAware >
7-
<#assign indexFilterName = "label_regex">
7+
<#assign indexFilterName = "initial">
88
<#else>
9-
<#assign indexFilterName = "raw_label_regex">
9+
<#assign indexFilterName = "raw_initial">
1010
</#if>
1111
<script>
1212
let searchFormId = "filter-form";
@@ -112,12 +112,6 @@
112112
</#list>
113113
<#elseif filters[indexFilterName]?? && filters[indexFilterName].inputText?has_content>
114114
<#assign selectedLetter = filters[indexFilterName].inputText >
115-
<#list i18n().browse_results_alphabetical_index?split(",") as c>
116-
<#assign regexValue = "(" + c?lower_case?cap_first + "|" + c?lower_case + "|" + c?upper_case + ").*">
117-
<#if filters[indexFilterName].inputText == regexValue >
118-
<#assign selectedLetter = c?upper_case >
119-
</#if>
120-
</#list>
121115
<li>
122116
<p class="no-individuals">${i18n().there_are_no_entries_starting_with} ${selectedLetter}</p>
123117
<p class="no-individuals">${i18n().try_another_letter}</p>
@@ -190,10 +184,9 @@
190184
</li>
191185
<#assign idCounter = 1>
192186
<#list i18n().browse_results_alphabetical_index?split(",") as c>
193-
<#assign regexValue = "(" + c?lower_case?cap_first + "|" + c?lower_case + "|" + c?upper_case + ").*">
194187
<li>
195-
<a href="#" <#if indexFilter.inputText == regexValue > class="selected" </#if> >
196-
<@getAlphabetInput indexFilter regexValue sl.getValueID(indexFilter.id, idCounter) />
188+
<a href="#" <#if indexFilter.inputText == c > class="selected" </#if> >
189+
<@getAlphabetInput indexFilter c sl.getValueID(indexFilter.id, idCounter) />
197190
<@getAlphabetLabel sl.getValueID(indexFilter.id, idCounter) c?upper_case />
198191
</a>
199192
</li>

0 commit comments

Comments
 (0)