PageSourceSearch

https://govmu.org/SiteAssets/GovStyles/scripts/search/searchWorker.js

js govmu.org collected 2026-10-01 09:01:43 UTC 4,468 bytes, 162 lines download raw bytes

1self.onmessage = function(e) {
2	try{
3		
4		console.log("web worker created successfully");
5		
6		var passedParam = null;
7		var myItemsTitle = [];
8		var myItems = [];
9		
10			
11		// the passed-in data is available via e.data	
12		if(e.data !== null){	
13			passedParam = e.data;
14						
15			var restUrl = buildRESTUrl(passedParam.webUrl, passedParam.searchValue, passedParam.listName, passedParam.language);
16			//console.log("restUrl: " + restUrl);
17			
18			var items = GetListItems(restUrl);
19			
20			if(items != "undefined"){
21				if(items !== null){
22					if(items.length > 0){
23						for(var i = 0 ; i < items.length; i++){
24							if(!myItemsTitle.includes(items[i].Title)){
25								myItemsTitle.push(items[i].Title);
26								myItems.push(items[i]);
27							}												
28						}
29					}							
30				}
31			}
32			
33			//searching word by word		
34			if(myItems == null || myItems.length == 0){
35				var searchValue = passedParam.searchValue.split(" ");
36				
37				if(searchValue != "undefined"){
38					if(searchValue != null){
39						if(searchValue.length > 0){
40							for(var x=0;x<searchValue.length; x++){
41
42								restUrl = buildRESTUrl(passedParam.webUrl, searchValue[x], passedParam.listName, passedParam.language);
43								//console.log("restUrl: " + restUrl);
44								
45								items = GetListItems(restUrl);
46								
47								if(items != "undefined"){
48									if(items != null){
49										if(items.length > 0){
50											for(var i = 0 ; i < items.length; i++){
51												if(!myItemsTitle.includes(items[i].Title)){
52													myItemsTitle.push(items[i].Title);
53													myItems.push(items[i]);
54												}												
55											}
56										}							
57									}
58								}							
59							}   	
60						}
61					}
62				}				
63			}		
64
65			postMessage(myItems);	
66		}	
67	}
68	catch(e){
69		console.error("web worker error: " + e.toString());
70	}	
71}
72
73
74//done
75function GetListItems(restUrl) {
76	var myItems;
77	try{
78		if(restUrl !== ""){		
79			var xhr = new XMLHttpRequest();
80			xhr.open('GET', restUrl, false);
81			xhr.setRequestHeader('Accept', 'application/json;odata=verbose');
82			xhr.onload = function() {
83				if (xhr.status === 200) {
84					myItems = JSON.parse(xhr.responseText);					
85				}
86				else {
87					console.log('Request failed.  Returned status of ' + xhr.status);
88				}
89			};
90			xhr.send();
91		}
92		else{
93			console.log("eServiceUrl is null");
94		}	
95	}
96	catch(e){
97		console.error("Web worker GetListItems() error: " + e.toString());
98	}
99	return myItems.d.results;
100}//end function GetListItems()  
101
102
103//done
104function buildRESTUrl(webUrl, search, listName, language){
105	var url = "";	
106	try{     	
107		if(search != "undefined"){
108			if(search != null && search != ""){
109				
110				if(search.includes("'")){
111					search = search.replace("'", "''");
112				}
113									
114				if(webUrl != "undefined"){
115					
116					if(webUrl != null && search != ""){
117						
118						if(listName === "map"){
119							url = webUrl+"/_api/web/lists/GetByTitle('"+listName+"')/items?";
120							url += "$select=Title,TitleFR,Latitude,Longitude,Category/Title,Category/TitleFR";
121							url += "&$filter=substringof('"+search+ "',Title)";
122							url += " or substringof('"+search+ "',TitleFR)";
123							url += " or substringof('"+search+ "',Keywords)";
124							url += " or substringof('"+search+ "',KeywordsFR)";
125							url += " or substringof('"+search+ "',Category/Title)";
126							url += " or substringof('"+search+ "',Category/TitleFR)";
127							url += "&$expand=Category";
128							url += "&$orderby=Title asc";
129							url += "&$top=500";
130						}	
131						
132						if(listName === "topiceservices"){
133							if(language != ""){
134								if(language=="en"){
135									webUrl += "/EN";
136								}
137								
138								if(language=="fr"){
139									webUrl += "/FR";
140								}
141								
142								url = webUrl+"/_api/web/lists/GetByTitle('"+listName+"')/items?";
143								url += "$select=Title,description,url,topics/Title";
144								url += "&$filter=substringof('"+search+ "',Title)";
145								url += " or substringof('"+search+ "',description)";
146								url += " or substringof('"+search+ "',topics/Title)";
147								url += "&$expand=topics";
148								url += "&$orderby=Title asc";
149								url += "&$top=500";
150								
151							}						
152						}
153					}
154				}				
155			}
156		}	
157	}
158	catch(e){
159		console.error("web worker buildRESTUrl() error: " + e.toString());
160	}   	
161	return url;   	
162}//end function buildRESTUrl

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.