abdelhaqueidali commited on
Commit
1450858
·
verified ·
1 Parent(s): e39bd11

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +32 -46
index.html CHANGED
@@ -289,9 +289,8 @@ function performSearch() {
289
  }
290
 
291
  const searchType = Array.from(searchTypeRadios).find(radio => radio.checked).value;
292
- // const useWordBoundary = wordBoundaryCheckbox.checked; // Removed
293
 
294
- let filteredData = [];
295
 
296
  if (searchType === 'contains') {
297
  const exactMatches = [];
@@ -299,68 +298,55 @@ function performSearch() {
299
  const endsWithMatches = [];
300
  const otherContainsMatches = [];
301
 
302
-
303
  excelData.forEach(row => {
304
- let rowMatches = false;
305
  row.forEach((cell, index) => {
306
-
307
  const columnIndex = String.fromCharCode('A'.charCodeAt(0) + index);
308
- if(columnIndex === mainWordColumn || mapping[columnIndex]){ //Prioritize the main columns
309
-
310
  const normalizedCell = normalizeText(cell);
311
- // Removed word boundary logic
312
-
313
-
314
- if (normalizedCell.includes(searchTerm)) {
315
- if (normalizedCell === searchTerm) {
316
- exactMatches.push(row);
317
- }
318
- else if(normalizedCell.startsWith(searchTerm)){
319
- startsWithMatches.push(row);
320
- }
321
- else if(normalizedCell.endsWith(searchTerm)){
322
- endsWithMatches.push(row)
323
- }
324
- else{
325
- otherContainsMatches.push(row)
326
- }
327
- rowMatches = true;
328
- }
329
  }
330
  });
331
-
332
-
333
  });
334
- filteredData = [...new Set([...exactMatches, ...startsWithMatches,...endsWithMatches, ...otherContainsMatches])]; // Remove duplicates, and combine
335
 
336
  }
337
  else if (searchType === 'startsWith') {
338
  filteredData = excelData.filter(row =>
339
  row.some((cell, index) => {
340
  const columnIndex = String.fromCharCode('A'.charCodeAt(0) + index);
341
- if(columnIndex === mainWordColumn || mapping[columnIndex]){ //Prioritize the main columns
342
  const normalizedCell = normalizeText(cell);
343
- // Removed word boundary logic
344
- return normalizedCell.startsWith(searchTerm);
345
  }
346
  return false;
347
  }));
348
  } else if (searchType === 'exact') {
349
-
350
- filteredData = excelData.filter(row =>
351
- row.some((cell, index) => {
352
- const columnIndex = String.fromCharCode('A'.charCodeAt(0) + index);
353
- if(columnIndex === mainWordColumn || mapping[columnIndex]){ //Prioritize the main columns
354
-
355
- const normalizedCell = normalizeText(cell);
356
- // Removed word boundary logic
357
- return normalizedCell === searchTerm; // Strict equality
358
-
359
- }
360
- return false;
361
- }));
362
-
363
-
364
  }
365
 
366
  displayData(filteredData);
 
289
  }
290
 
291
  const searchType = Array.from(searchTypeRadios).find(radio => radio.checked).value;
 
292
 
293
+ let filteredData = [];
294
 
295
  if (searchType === 'contains') {
296
  const exactMatches = [];
 
298
  const endsWithMatches = [];
299
  const otherContainsMatches = [];
300
 
 
301
  excelData.forEach(row => {
 
302
  row.forEach((cell, index) => {
 
303
  const columnIndex = String.fromCharCode('A'.charCodeAt(0) + index);
304
+ if(columnIndex === mainWordColumn || mapping[columnIndex]){
 
305
  const normalizedCell = normalizeText(cell);
306
+ if (normalizedCell.includes(searchTerm)) {
307
+ if (normalizedCell === searchTerm) {
308
+ exactMatches.push(row);
309
+ }
310
+ else if(normalizedCell.startsWith(searchTerm)){
311
+ startsWithMatches.push(row);
312
+ }
313
+ else if(normalizedCell.endsWith(searchTerm)){
314
+ endsWithMatches.push(row)
315
+ }
316
+ else{
317
+ otherContainsMatches.push(row)
318
+ }
319
+ }
 
 
 
 
320
  }
321
  });
 
 
322
  });
323
+ filteredData = [...new Set([...exactMatches, ...startsWithMatches,...endsWithMatches, ...otherContainsMatches])];
324
 
325
  }
326
  else if (searchType === 'startsWith') {
327
  filteredData = excelData.filter(row =>
328
  row.some((cell, index) => {
329
  const columnIndex = String.fromCharCode('A'.charCodeAt(0) + index);
330
+ if(columnIndex === mainWordColumn || mapping[columnIndex]){
331
  const normalizedCell = normalizeText(cell);
332
+ return normalizedCell.startsWith(searchTerm);
 
333
  }
334
  return false;
335
  }));
336
  } else if (searchType === 'exact') {
337
+ // EXACT SEARCH (using word boundaries)
338
+ const regex = new RegExp(`\\b${searchTerm}\\b`, 'i'); // Case-insensitive
339
+
340
+ filteredData = excelData.filter(row =>
341
+ row.some((cell, index) => {
342
+ const columnIndex = String.fromCharCode('A'.charCodeAt(0) + index);
343
+ if (columnIndex === mainWordColumn || mapping[columnIndex]) {
344
+ const normalizedCell = normalizeText(cell);
345
+ return regex.test(normalizedCell);
346
+ }
347
+ return false;
348
+ })
349
+ );
 
 
350
  }
351
 
352
  displayData(filteredData);