search-algoritm 1.1.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # Changelog
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
+
5
+ ---
6
+ ## [1.2.0] - 2026-02-25
7
+ ### Added
8
+ - Search now includes **filename** in addition to title and description.
9
+ - Fuzzy matching and token-based scoring are applied to filenames as well.
10
+ - Improved relevance calculation when query matches filename, title, or description.
11
+ - Module normalization continues to support accent-insensitive search and stopword filtering.
12
+
4
13
  ---
5
14
  ## [1.1.3] - 2025-12-04
6
15
  ### Error
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![GitHub Repository](https://img.shields.io/badge/GitHub-Repository-blue?logo=github)](https://github.com/FelixLind1/SearchAlgoritm)
8
8
 
9
9
  A lightweight Node.js library for **fuzzy searching** arrays of objects.
10
- It calculates relevance scores based on how well a query matches the `title` and `description` of each item.
10
+ It calculates relevance scores based on how well a query matches the `title`, `description`, and `file` of each item.
11
11
 
12
12
  **Features:**
13
13
 
@@ -15,7 +15,7 @@ It calculates relevance scores based on how well a query matches the `title` and
15
15
  - **Accent-insensitive** searches (`é → e`)
16
16
  - Token-based word matching for partial or multi-word queries
17
17
  - Multi-word sequence detection (`"mac pro"` → `"MacBook Pro"`)
18
- - Weighted scoring: title matches are more important than description
18
+ - Weighted scoring: **title > description file**
19
19
  - Stopword filtering for more relevant results
20
20
 
21
21
  ---
@@ -85,7 +85,7 @@ app.listen(PORT, () => {
85
85
  });
86
86
  ```
87
87
 
88
- ✅ Fast searches using in-memory cache. Ideal for **medium to large datasets** where performance matters.
88
+ ✅ Fast searches using in-memory cache. Ideal for **medium to large datasets**.
89
89
 
90
90
  ---
91
91
 
@@ -125,7 +125,7 @@ app.listen(PORT, () => {
125
125
  });
126
126
  ```
127
127
 
128
- ✅ Reads JSON on each request. Best for **small datasets** or when data changes frequently.
128
+ ✅ Reads JSON on each request. Best for **small datasets** or frequently changing data.
129
129
 
130
130
  ---
131
131
 
@@ -176,7 +176,8 @@ async function initSearch() {
176
176
  ? results.map(item => `
177
177
  <li class="result-item">
178
178
  <strong>${item.title}</strong><br>
179
- <span>${item.description}</span>
179
+ <span>${item.description}</span><br>
180
+ <em>File: ${item.file}</em>
180
181
  </li>
181
182
  `).join('')
182
183
  : `<li class="no-result">No matches found</li>`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "search-algoritm",
3
- "version": "1.1.3",
3
+ "version": "1.2.0",
4
4
  "description": "Simple and lightweight fuzzy search algoritm for titles and descriptions.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,4 +1,3 @@
1
- // searchAlgoritm.js
2
1
  console.log('[searchAlgoritm] 🔍 Module loaded');
3
2
 
4
3
  /**
@@ -98,7 +97,7 @@ const matchScore = (text, query) => {
98
97
 
99
98
  /**
100
99
  * Compute weighted score for an item
101
- * Title is weighted higher than description
100
+ * Title is weighted highest, then description and file equally
102
101
  * @param {object} item
103
102
  * @param {string} query
104
103
  * @returns {number}
@@ -106,7 +105,10 @@ const matchScore = (text, query) => {
106
105
  const calculateItemScore = (item, query) => {
107
106
  const title = item._lcTitle ?? normalize(item.title);
108
107
  const desc = item._lcDesc ?? normalize(item.description);
109
- return matchScore(title, query) * 3 + matchScore(desc, query);
108
+ const file = item._lcFile ?? normalize(item.file ?? '');
109
+
110
+ // Weight: title *3, description *1.5, file *1.5
111
+ return matchScore(title, query) * 3 + matchScore(desc, query) * 1.5 + matchScore(file, query) * 1.5;
110
112
  };
111
113
 
112
114
  /**
@@ -125,6 +127,7 @@ const searchAlgoritm = (query, dataList, enableLog = false) => {
125
127
  dataList.forEach(item => {
126
128
  item._lcTitle ??= normalize(item.title);
127
129
  item._lcDesc ??= normalize(item.description);
130
+ item._lcFile ??= normalize(item.file ?? ''); // include file
128
131
  });
129
132
 
130
133
  const results = dataList