diff --git a/config/vufind/searches.ini b/config/vufind/searches.ini index edd90ee5f4c6b1d2fda821f11764014db146f8d5..2c5194718245c248beaeccbe4773408c35597e02 100644 --- a/config/vufind/searches.ini +++ b/config/vufind/searches.ini @@ -56,7 +56,7 @@ default_top_recommend[] = SpellingSuggestions ;default_top_recommend[] = VisualFacets:Visual_Settings default_side_recommend[] = SideFacets:Results:CheckboxFacets default_noresults_recommend[] = SwitchType -default_noresults_recommend[] = SwitchQuery +default_noresults_recommend[] = SwitchQuery:::fuzzy default_noresults_recommend[] = SpellingSuggestions ; Set this to true in order to highlight keywords from the search query when they @@ -351,14 +351,16 @@ CallNumber = callnumber-sort ; ; AlphaBrowseLink:index ; Use the query to generate a link to the specified alphabrowse index -; SwitchQuery:[backend]:[checks to skip]:[transforms to add] +; SwitchQuery:[backend]:[opt-out checks to skip]:[opt-in checks to add] ; This module analyzes the user's query and offers suggestions for ways to ; improve it. [backend] is the name of the search backend currently in use, -; which will help with accurate analysis (default = Solr). [checks to skip] -; is a comma-separated list of checks to disable; see the check*() methods -; in the module's code for a complete list of available checks. -; [transforms to add] is a comma-separated list of transforms to enable; -; currently there is only one: truncatechar +; which will help with accurate analysis (default = Solr). [opt-out checks +; to skip] is a comma-separated list of checks which are on by default but +; which you wish to disable; see the check*() methods in the module's code +; for a complete list of available checks. [opt-in checks to add] is a +; comma-separated list of transforms that are off by default but which you +; wish to enable; see the transform*() methods in the module's code for a +; complete list of available checks. ; SwitchType:[field]:[field description] ; If the current search type is not the same as [field], display a link ; suggesting that the user try switching to [field]. [field description] diff --git a/languages/en.ini b/languages/en.ini index c0b7c8f31b51593f0474ed3352afaf553147de6d..942426857bf471035b3f31570bf26e841274e628 100644 --- a/languages/en.ini +++ b/languages/en.ini @@ -920,6 +920,7 @@ summon_database_recommendations = "You may find additional resources here:" Supplements = "Supplements" Supplied by Amazon = "Supplied by Amazon" Switch view to = "Switch view to" +switchquery_fuzzy = "Performing a fuzzy search may retrieve terms with similar spellings" switchquery_intro = "You may be able to get more results by adjusting your search query." switchquery_lowercasebools = "If you are trying to use Boolean operators, they must be ALL CAPS" switchquery_truncatechar = "Shorten your search query to broaden your results" diff --git a/module/VuFind/src/VuFind/Recommend/SwitchQuery.php b/module/VuFind/src/VuFind/Recommend/SwitchQuery.php index 7b6491bd304bfaa8032296522b3edf0523d917c4..c32dff13f83f8d2839c96aa78a62ec2c9ac6a3a8 100644 --- a/module/VuFind/src/VuFind/Recommend/SwitchQuery.php +++ b/module/VuFind/src/VuFind/Recommend/SwitchQuery.php @@ -208,6 +208,27 @@ class SwitchQuery implements RecommendInterface return false; } + /** + * Will a fuzzy search help? + * + * @param string $query Query to check + * + * @return string|bool + */ + protected function transformFuzzy($query) + { + // Don't stack tildes: + if (strpos($query, '~') !== false) { + return false; + } + $query = trim($query, ' ?*'); + // Fuzzy search only works for single keywords, not phrases: + if (substr($query, -1) == '"') { + return false; + } + return (substr($query, -1) != '~') ? $query . '~' : false; + } + /** * Does the query contain lowercase boolean operators that should be uppercased? * @@ -271,11 +292,11 @@ class SwitchQuery implements RecommendInterface */ protected function checkWildcard($query) { + $query = trim($query, ' ?~'); // Don't pile wildcards on phrases: if (substr($query, -1) == '"') { return false; } - $query = trim($query, ' ?'); return (substr($query, -1) != '*') ? $query . '*' : false; }