1+ import { SearchTarget } from '../models/search-target.model' ;
2+
3+ /**
4+ * Helper function to extract and format search queries for external sources
5+ * Converts Primo query format to simple search terms
6+ * @param queries Array of Primo-formatted query strings
7+ * @returns URL-encoded search string
8+ */
9+ function buildSearchQuery ( queries : string [ ] ) : string {
10+ try {
11+ let fullSearchQuery = '' ;
12+
13+ // Process each query element
14+ queries . forEach ( ( queryElement ) => {
15+ // Primo query format: "field,operator,searchTerm,boolean"
16+ // Example: "any,contains,test search,AND"
17+
18+ const firstCommaIndex = queryElement . indexOf ( ',' ) ;
19+ const secondCommaIndex = queryElement . indexOf ( ',' , firstCommaIndex + 1 ) ;
20+ let searchStr = queryElement . slice ( secondCommaIndex + 1 ) ;
21+
22+ // Remove trailing boolean operators (,AND or ,OR)
23+ if ( searchStr . endsWith ( ',AND' ) || searchStr . endsWith ( ',OR' ) ) {
24+ const finalComma = searchStr . lastIndexOf ( ',' ) ;
25+ searchStr = searchStr . slice ( 0 , finalComma ) ;
26+ }
27+
28+ // Append to full query with space separator
29+ fullSearchQuery = fullSearchQuery . concat ( searchStr + ' ' ) ;
30+ } ) ;
31+
32+ // Trim and encode for URL
33+ return encodeURIComponent ( fullSearchQuery . trim ( ) ) ;
34+ } catch ( e ) {
35+ console . error ( 'Error building search query:' , e ) ;
36+ return '' ;
37+ }
38+ }
39+
40+ /**
41+ * Configuration array of external search sources
42+ * Each source can be clicked from the filter panel to search with current query
43+ */
44+ export const EXTERNAL_SEARCH_SOURCES : SearchTarget [ ] = [
45+ {
46+ name : 'WorldCat' ,
47+ nameHe : 'WorldCat' ,
48+ url : 'https://kansasstateuniversity.on.worldcat.org/search?queryString=kw:' ,
49+ img : 'assets/images/external-sources/worldcat-logo.png' ,
50+ img_2 : 'assets/images/external-sources/worldcat-logo.png' ,
51+ alt : 'Worldcat' ,
52+ mapping : ( queries : string [ ] , filters : string [ ] ) : string => {
53+ return buildSearchQuery ( queries ) ;
54+ }
55+ } ,
56+ {
57+ name : 'Google Scholar' ,
58+ nameHe : 'Google Scholar' ,
59+ url : 'https://scholar.google.com/scholar?q=' ,
60+ img : 'assets/images/external-sources/logo-googlescholar.png' ,
61+ img_2 : 'assets/images/external-sources/logo-googlescholar.png' ,
62+ alt : 'Google Scholar' ,
63+ mapping : ( queries : string [ ] , filters : string [ ] ) : string => {
64+ return buildSearchQuery ( queries ) ;
65+ }
66+ } ,
67+ {
68+ name : 'EBSCO' ,
69+ nameHe : 'EBSCO' ,
70+ url : 'https://research.ebsco.com/c/b2utja/search/results?q=' ,
71+ img : 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/EBSCO_Information_Services_20xx_logo.svg/200px-EBSCO_Information_Services_20xx_logo.svg.png' ,
72+ img_2 : 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/EBSCO_Information_Services_20xx_logo.svg/200px-EBSCO_Information_Services_20xx_logo.svg.png' ,
73+ alt : 'EBSCO' ,
74+ mapping : ( queries : string [ ] , filters : string [ ] ) : string => {
75+ return buildSearchQuery ( queries ) ;
76+ }
77+ }
78+ // Crossref is commented out in the original - can be added later if needed
79+ /*
80+ {
81+ name: 'Crossref',
82+ nameHe: 'Crossref',
83+ url: 'https://search.crossref.org/?from_ui=yes&q=',
84+ img: 'assets/images/external-sources/crossref_logo_16_16.png',
85+ img_2: 'assets/images/external-sources/crossref_logo_16_16.png',
86+ alt: 'Crossref',
87+ mapping: (queries: string[], filters: string[]): string => {
88+ return buildSearchQuery(queries);
89+ }
90+ }
91+ */
92+ ] ;
0 commit comments