js-solr-highlighter
Advanced tools
Comparing version 0.8.7 to 0.8.8
@@ -100,3 +100,3 @@ "use strict"; | ||
// remove any char that is neither letter nor number at the start and end of each term | ||
const terms = term.split(/\s/).map(t => t.replace(/^[^a-zA-Z0-9]+/, '').replace(/[^a-zA-Z0-9]+$/, '')); | ||
const terms = term.split(/\s/).map(t => t.replace(/^[^a-zA-Z0-9]+/, '').replace(/[^a-zA-Z0-9\*]+$/, '')); | ||
return words.concat(terms); | ||
@@ -142,5 +142,15 @@ } | ||
} | ||
// highlight one word by another | ||
// some filters may be moved up*** | ||
words = words.filter(word => word.length && !isStopWord(word) && !['AND', 'OR', 'NOT'].includes(word)); | ||
for (let i = 0; i < words.length; i++) { | ||
if (words[i].endsWith('*')) { | ||
words[i] = words[i].slice(0, words[i].length - 1); | ||
let index = content.indexOf(words[i]) + words[i].length; | ||
while (content[index] !== ' ' && index !== content.length - 1) { | ||
words[i] += content[index]; | ||
index++; | ||
} | ||
} | ||
} | ||
// highlight one word by another | ||
let newContent = content; | ||
@@ -147,0 +157,0 @@ if (words.length) { |
@@ -126,3 +126,3 @@ "use strict"; | ||
.split(/\s/) | ||
.map((t) => t.replace(/^[^a-zA-Z0-9]+/, '').replace(/[^a-zA-Z0-9]+$/, '')); | ||
.map((t) => t.replace(/^[^a-zA-Z0-9]+/, '').replace(/[^a-zA-Z0-9\*]+$/, '')); | ||
return words.concat(terms); | ||
@@ -187,5 +187,15 @@ } | ||
} | ||
// highlight one word by another | ||
// some filters may be moved up*** | ||
words = words.filter((word) => word.length && !isStopWord(word) && !['AND', 'OR', 'NOT'].includes(word)); | ||
for (let i = 0; i < words.length; i++) { | ||
if (words[i].endsWith('*')) { | ||
words[i] = words[i].slice(0, words[i].length - 1); | ||
let index = content.indexOf(words[i]) + words[i].length; | ||
while (content[index] !== ' ' && index !== content.length - 1) { | ||
words[i] += content[index]; | ||
index++; | ||
} | ||
} | ||
} | ||
// highlight one word by another | ||
let newContent = content; | ||
@@ -192,0 +202,0 @@ if (words.length) { |
@@ -579,2 +579,12 @@ import { isStopWord, highlightByQuery } from './dist/index.js' | ||
}) | ||
test('fuzzy query *', () => { | ||
const query = 'Bre*' | ||
const content = | ||
'Editorial: The Role of Breast Cancer Stem Cells in Clinical Outcomes.' | ||
const received = highlightByQuery(query, content) | ||
const expected = | ||
'Editorial: The Role of <span id="highlight-0" class="highlight">Breast</span> Cancer Stem Cells in Clinical Outcomes.' | ||
expect(received).toBe(expected) | ||
}) | ||
}) | ||
@@ -581,0 +591,0 @@ |
15
index.ts
@@ -147,3 +147,3 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
.map((t) => | ||
t.replace(/^[^a-zA-Z0-9]+/, '').replace(/[^a-zA-Z0-9]+$/, '') | ||
t.replace(/^[^a-zA-Z0-9]+/, '').replace(/[^a-zA-Z0-9\*]+$/, '') | ||
) | ||
@@ -218,3 +218,2 @@ return words.concat(terms) | ||
// highlight one word by another | ||
// some filters may be moved up*** | ||
@@ -225,2 +224,14 @@ words = words.filter( | ||
) | ||
for (let i = 0; i < words.length; i++) { | ||
if (words[i].endsWith('*')) { | ||
words[i] = words[i].slice(0, words[i].length - 1) | ||
let index = content.indexOf(words[i]) + words[i].length; | ||
while(content[index] !== ' ' && index !== content.length - 1) { | ||
words[i] += content[index] | ||
index++ | ||
} | ||
} | ||
} | ||
// highlight one word by another | ||
let newContent = content | ||
@@ -227,0 +238,0 @@ if (words.length) { |
{ | ||
"name": "js-solr-highlighter", | ||
"version": "0.8.7", | ||
"version": "0.8.8", | ||
"description": "A JavaScript library for highlighting HTML text based on the query in the lucene/solr query syntax", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57155
1248