js-solr-highlighter
Advanced tools
Comparing version 0.7.1 to 0.7.2
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.hasNonStopWords = hasNonStopWords; | ||
exports.isStopWord = isStopWord; | ||
exports.highlightByQuery = highlightByQuery; | ||
@@ -18,4 +18,4 @@ exports.STOP_WORDS = void 0; | ||
function hasNonStopWords(string) { | ||
return STOP_WORDS.includes(string); | ||
function isStopWord(string) { | ||
return STOP_WORDS.includes(string.toLowerCase()); | ||
} // validFields are those parsed as fields. If undefined, all will be parsed as fields if they are like x:x | ||
@@ -28,4 +28,8 @@ // highlightedFields are those among validFields whose values will be highlighted. If undefined, the values of all valid fields will be highlighted | ||
validFields, | ||
highlightedFields | ||
highlightAll, | ||
highlightClass, | ||
highlightedFields, | ||
highlightIdPattern | ||
} = options; | ||
const searchFunc = highlightAll === undefined || highlightAll ? 'searchAll' : 'search'; | ||
let words = []; | ||
@@ -169,3 +173,3 @@ | ||
words = words.filter(word => word.length && !hasNonStopWords(word.toLowerCase()) && !['AND', 'OR', 'NOT'].includes(word)); | ||
words = words.filter(word => word.length && !isStopWord(word) && !['AND', 'OR', 'NOT'].includes(word)); | ||
let newContent = content; | ||
@@ -178,3 +182,3 @@ | ||
words.forEach(word => { | ||
const highlightIndexes = highlighter.searchAll(word, { | ||
let res = highlighter[searchFunc](word, { | ||
directSearchOptions: { | ||
@@ -184,3 +188,4 @@ caseSensitive: false | ||
}); | ||
highlightIndexes.forEach(highlightIndex => { | ||
res = searchFunc === 'search' ? [res] : res; | ||
res.forEach(highlightIndex => { | ||
const loc = highlighter.highlights[highlightIndex].loc; | ||
@@ -192,3 +197,3 @@ const text = highlighter.stripedHTML; | ||
return !c.match(letters); | ||
}; // make sure we do not highlight part of a word | ||
}; // make sure we do not highlight part of a word; can be moved up | ||
@@ -204,4 +209,4 @@ | ||
returnContent: true, | ||
color: 'transparent', | ||
highlightClass: 'extra-bold' | ||
highlightIdPattern, | ||
highlightClass | ||
}); | ||
@@ -208,0 +213,0 @@ } |
12
index.js
@@ -48,3 +48,9 @@ import TextAnnotator from 'text-annotator' | ||
function highlightByQuery(query, content, options = {}) { | ||
const { validFields, highlightAll, highlightedFields } = options | ||
const { | ||
validFields, | ||
highlightAll, | ||
highlightClass, | ||
highlightedFields, | ||
highlightIdPattern | ||
} = options | ||
const searchFunc = | ||
@@ -246,4 +252,4 @@ highlightAll === undefined || highlightAll ? 'searchAll' : 'search' | ||
returnContent: true, | ||
color: 'transparent', | ||
highlightClass: 'extra-bold' | ||
highlightIdPattern, | ||
highlightClass | ||
}) | ||
@@ -250,0 +256,0 @@ } |
@@ -164,3 +164,3 @@ import { isStopWord, highlightByQuery } from './index.js' | ||
const expected = | ||
'epiCaPture: A Urine DNA <span id="highlight-0" class="extra-bold">Methylation</span> <span id="highlight-1" class="extra-bold">Test</span> for Early Detection of Aggressive Prostate Cancer.' | ||
'epiCaPture: A Urine DNA <span id="highlight-0" class="highlight">Methylation</span> <span id="highlight-1" class="highlight">Test</span> for Early Detection of Aggressive Prostate Cancer.' | ||
expect(received).toBe(expected) | ||
@@ -175,3 +175,3 @@ }) | ||
const expected = | ||
'A molecular map of lymph node <span id="highlight-0" class="extra-bold">blood</span> vascular endothelium at single cell resolution' | ||
'A molecular map of lymph node <span id="highlight-0" class="highlight">blood</span> vascular endothelium at single cell resolution' | ||
expect(received).toBe(expected) | ||
@@ -186,3 +186,3 @@ }) | ||
const expected = | ||
'Towards emerging EEG applications: a novel printable flexible Ag/AgCl dry <span id="highlight-0" class="extra-bold">electrode array</span> for robust recording of EEG signals at forehead sites.' | ||
'Towards emerging EEG applications: a novel printable flexible Ag/AgCl dry <span id="highlight-0" class="highlight">electrode array</span> for robust recording of EEG signals at forehead sites.' | ||
expect(received).toBe(expected) | ||
@@ -217,3 +217,3 @@ }) | ||
const expected = | ||
'Autophagy-mediated occludin degradation contributes to <span id="highlight-0" class="extra-bold">blood</span>-<span id="highlight-1" class="extra-bold">brain</span> barrier disruption during ischemia in bEnd.3 <span id="highlight-2" class="extra-bold">brain</span> endothelial cells and rat ischemic stroke models.' | ||
'Autophagy-mediated occludin degradation contributes to <span id="highlight-0" class="highlight">blood</span>-<span id="highlight-1" class="highlight">brain</span> barrier disruption during ischemia in bEnd.3 <span id="highlight-2" class="highlight">brain</span> endothelial cells and rat ischemic stroke models.' | ||
expect(received).toBe(expected) | ||
@@ -236,3 +236,3 @@ }) | ||
const expected = | ||
'Platelet Volume Is Reduced In Metastasing Breast <span id="highlight-0" class="extra-bold">Cancer</span>: <span id="highlight-1" class="extra-bold">Blood</span> Profiles Reveal Significant Shifts.' | ||
'Platelet Volume Is Reduced In Metastasing Breast <span id="highlight-0" class="highlight">Cancer</span>: <span id="highlight-1" class="highlight">Blood</span> Profiles Reveal Significant Shifts.' | ||
expect(received).toBe(expected) | ||
@@ -246,3 +246,3 @@ }) | ||
const expected = | ||
'New <span id="highlight-0" class="extra-bold">cancer</span> <span id="highlight-1" class="extra-bold">blood</span> test developed.' | ||
'New <span id="highlight-0" class="highlight">cancer</span> <span id="highlight-1" class="highlight">blood</span> test developed.' | ||
expect(received).toBe(expected) | ||
@@ -257,3 +257,3 @@ }) | ||
const expected = | ||
'Efficacy of kinesio taping in early stage breast <span id="highlight-0" class="extra-bold">cancer</span> associated lymphedema: A randomized single blinded study.' | ||
'Efficacy of kinesio taping in early stage breast <span id="highlight-0" class="highlight">cancer</span> associated lymphedema: A randomized single blinded study.' | ||
expect(received).toBe(expected) | ||
@@ -268,3 +268,3 @@ }) | ||
const expected = | ||
'A multicentre parallel-group randomised trial assessing multiparametric MRI characterisation and image-guided <span id="highlight-0" class="extra-bold">biopsy</span> of prostate in men suspected of having prostate cancer: MULTIPROS study protocol.' | ||
'A multicentre parallel-group randomised trial assessing multiparametric MRI characterisation and image-guided <span id="highlight-0" class="highlight">biopsy</span> of prostate in men suspected of having prostate cancer: MULTIPROS study protocol.' | ||
expect(received).toBe(expected) | ||
@@ -279,3 +279,3 @@ }) | ||
const expected = | ||
'[Predictive values of routine <span id="highlight-0" class="extra-bold">blood</span> <span id="highlight-1" class="extra-bold">test</span> results for iron deficiency in children].' | ||
'[Predictive values of routine <span id="highlight-0" class="highlight">blood</span> <span id="highlight-1" class="highlight">test</span> results for iron deficiency in children].' | ||
expect(received).toBe(expected) | ||
@@ -301,3 +301,3 @@ }) | ||
const expected = | ||
'Diabetes and <span id="highlight-2" class="extra-bold"><span id="highlight-0" class="extra-bold">Cancer</span></span>: <span id="highlight-3" class="extra-bold"><span id="highlight-1" class="extra-bold">Cancer</span></span> Should Be Screened in Routine Diabetes Assessment.' | ||
'Diabetes and <span id="highlight-2" class="highlight"><span id="highlight-0" class="highlight">Cancer</span></span>: <span id="highlight-3" class="highlight"><span id="highlight-1" class="highlight">Cancer</span></span> Should Be Screened in Routine Diabetes Assessment.' | ||
expect(received).toBe(expected) | ||
@@ -312,3 +312,3 @@ }) | ||
const expected = | ||
'Genetic disruption of the <span id="highlight-0" class="extra-bold">Blood</span> Brain Barrier leads to protective barrier formation at the Glia Limitans' | ||
'Genetic disruption of the <span id="highlight-0" class="highlight">Blood</span> Brain Barrier leads to protective barrier formation at the Glia Limitans' | ||
expect(received).toBe(expected) | ||
@@ -324,3 +324,3 @@ }) | ||
const expected = | ||
'The Campbell Paradigm as a <span id="highlight-2" class="extra-bold">Behavior</span>-Predictive Reinterpretation of the Classical Tripartite Model of <span id="highlight-0" class="extra-bold">Attitudes</span>.' | ||
'The Campbell Paradigm as a <span id="highlight-2" class="highlight">Behavior</span>-Predictive Reinterpretation of the Classical Tripartite Model of <span id="highlight-0" class="highlight">Attitudes</span>.' | ||
expect(received).toBe(expected) | ||
@@ -335,3 +335,3 @@ }) | ||
const expected = | ||
'A <span id="highlight-0" class="extra-bold">theory-based</span> <span id="highlight-1" class="extra-bold">study</span> of <span id="highlight-2" class="extra-bold">doctors</span>\' intentions to engage in professional behaviours.' | ||
'A <span id="highlight-0" class="highlight">theory-based</span> <span id="highlight-1" class="highlight">study</span> of <span id="highlight-2" class="highlight">doctors</span>\' intentions to engage in professional behaviours.' | ||
expect(received).toBe(expected) | ||
@@ -346,3 +346,3 @@ }) | ||
const expected = | ||
'High definition ultrasound imaging of the individual elements of the brachial plexus <span id="highlight-0" class="extra-bold">above</span> the clavicle.' | ||
'High definition ultrasound imaging of the individual elements of the brachial plexus <span id="highlight-0" class="highlight">above</span> the clavicle.' | ||
expect(received).toBe(expected) | ||
@@ -374,3 +374,3 @@ }) | ||
const expected = | ||
'Genetic disruption of the Blood <span id="highlight-0" class="extra-bold">Brain</span> <span id="highlight-1" class="extra-bold">Barrier</span> leads to protective <span id="highlight-2" class="extra-bold">barrier</span> formation at the Glia Limitans' | ||
'Genetic disruption of the Blood <span id="highlight-0" class="highlight">Brain</span> <span id="highlight-1" class="highlight">Barrier</span> leads to protective <span id="highlight-2" class="highlight">barrier</span> formation at the Glia Limitans' | ||
expect(received).toBe(expected) | ||
@@ -386,3 +386,3 @@ }) | ||
const expected = | ||
'<span id="highlight-0" class="extra-bold">Histone</span> <span id="highlight-1" class="extra-bold">Methyltransferases</span> as Therapeutic Targets for Kidney Diseases.' | ||
'<span id="highlight-0" class="highlight">Histone</span> <span id="highlight-1" class="highlight">Methyltransferases</span> as Therapeutic Targets for Kidney Diseases.' | ||
expect(received).toBe(expected) | ||
@@ -397,3 +397,3 @@ }) | ||
const expected = | ||
'Continuous renal replacement therapy in patients with <span id="highlight-0" class="extra-bold">HIV/AIDS</span>.' | ||
'Continuous renal replacement therapy in patients with <span id="highlight-0" class="highlight">HIV/AIDS</span>.' | ||
expect(received).toBe(expected) | ||
@@ -408,3 +408,3 @@ }) | ||
const expected = | ||
'<span id="highlight-0" class="extra-bold">Blood</span> <span id="highlight-1" class="extra-bold">pressure-related</span> electrocardiographic findings in healthy young individuals.' | ||
'<span id="highlight-0" class="highlight">Blood</span> <span id="highlight-1" class="highlight">pressure-related</span> electrocardiographic findings in healthy young individuals.' | ||
expect(received).toBe(expected) | ||
@@ -419,3 +419,3 @@ }) | ||
const expected = | ||
'Use of magnoflorine-phospholipid <span id="highlight-0" class="extra-bold">complex</span> to permeate <span id="highlight-1" class="extra-bold">blood</span>-brain barrier and treat depression in the CUMS animal model.' | ||
'Use of magnoflorine-phospholipid <span id="highlight-0" class="highlight">complex</span> to permeate <span id="highlight-1" class="highlight">blood</span>-brain barrier and treat depression in the CUMS animal model.' | ||
expect(received).toBe(expected) | ||
@@ -430,3 +430,3 @@ }) | ||
const expected = | ||
'A network Based method to predict <span id="highlight-0" class="extra-bold">cancer</span> causal genes in GR Network.' | ||
'A network Based method to predict <span id="highlight-0" class="highlight">cancer</span> causal genes in GR Network.' | ||
expect(received).toBe(expected) | ||
@@ -441,3 +441,3 @@ }) | ||
const expected = | ||
'Management delays in patients with squamous cell <span id="highlight-0" class="extra-bold">cancer</span> of <span id="highlight-1" class="extra-bold">neck</span> node(s) and unknown primary site: a retrospective cohort study.' | ||
'Management delays in patients with squamous cell <span id="highlight-0" class="highlight">cancer</span> of <span id="highlight-1" class="highlight">neck</span> node(s) and unknown primary site: a retrospective cohort study.' | ||
expect(received).toBe(expected) | ||
@@ -462,3 +462,3 @@ }) | ||
const expected = | ||
'Antiobesity Effect of Garlic Extract Fermented by Lactobacillus plantarum <span id="highlight-0" class="extra-bold">BL2</span> in Diet-Induced Obese Mice.' | ||
'Antiobesity Effect of Garlic Extract Fermented by Lactobacillus plantarum <span id="highlight-0" class="highlight">BL2</span> in Diet-Induced Obese Mice.' | ||
expect(received).toBe(expected) | ||
@@ -473,3 +473,3 @@ }) | ||
const expected = | ||
'Appraisal of Metal Imbalances in the <span id="highlight-0" class="extra-bold">Blood</span> of Thyroid <span id="highlight-1" class="extra-bold">Cancer</span> Patients in Comparison with Healthy Subjects.' | ||
'Appraisal of Metal Imbalances in the <span id="highlight-0" class="highlight">Blood</span> of Thyroid <span id="highlight-1" class="highlight">Cancer</span> Patients in Comparison with Healthy Subjects.' | ||
expect(received).toBe(expected) | ||
@@ -484,3 +484,3 @@ }) | ||
const expected = | ||
'No viremia of pandemic (H1N1) 2009 was demonstrated in <span id="highlight-0" class="extra-bold">blood</span> donors who <span id="highlight-2" class="extra-bold">had</span> donated <span id="highlight-1" class="extra-bold">blood</span> during the probable incubation period.' | ||
'No viremia of pandemic (H1N1) 2009 was demonstrated in <span id="highlight-0" class="highlight">blood</span> donors who <span id="highlight-2" class="highlight">had</span> donated <span id="highlight-1" class="highlight">blood</span> during the probable incubation period.' | ||
expect(received).toBe(expected) | ||
@@ -495,3 +495,3 @@ }) | ||
const expected = | ||
'Supramolecular self-assembly of a hybrid \'hyalurosome\' for targeted photothermal therapy in non-small cell lung <span id="highlight-0" class="extra-bold">cancer</span>.' | ||
'Supramolecular self-assembly of a hybrid \'hyalurosome\' for targeted photothermal therapy in non-small cell lung <span id="highlight-0" class="highlight">cancer</span>.' | ||
expect(received).toBe(expected) | ||
@@ -506,3 +506,3 @@ }) | ||
const expected = | ||
'Parents\' perspectives on dried <span id="highlight-0" class="extra-bold">blood</span> spot self-sampling from children with epilepsy: A mixed method study.' | ||
'Parents\' perspectives on dried <span id="highlight-0" class="highlight">blood</span> spot self-sampling from children with epilepsy: A mixed method study.' | ||
expect(received).toBe(expected) | ||
@@ -517,3 +517,3 @@ }) | ||
const expected = | ||
'Strawberry milk-like <span id="highlight-0" class="extra-bold">blood in</span> a subject with diabetic lipemia: dramatic change to transparent color after insulin therapy.' | ||
'Strawberry milk-like <span id="highlight-0" class="highlight">blood in</span> a subject with diabetic lipemia: dramatic change to transparent color after insulin therapy.' | ||
expect(received).toBe(expected) | ||
@@ -532,3 +532,3 @@ }) | ||
const expected = | ||
'A molecular map of lymph node <span id="highlight-0" class="extra-bold">blood</span> vascular endothelium at single cell resolution' | ||
'A molecular map of lymph node <span id="highlight-0" class="highlight">blood</span> vascular endothelium at single cell resolution' | ||
expect(received).toBe(expected) | ||
@@ -546,3 +546,3 @@ }) | ||
const expected = | ||
'A molecular map of lymph node blood vascular endothelium at single <span id="highlight-0" class="extra-bold">cell</span> resolution' | ||
'A molecular map of lymph node blood vascular endothelium at single <span id="highlight-0" class="highlight">cell</span> resolution' | ||
expect(received).toBe(expected) | ||
@@ -559,3 +559,3 @@ }) | ||
const expected = | ||
'A molecular map of lymph node <span id="highlight-0" class="extra-bold">blood</span> vascular endothelium at single <span id="highlight-1" class="extra-bold">cell</span> resolution' | ||
'A molecular map of lymph node <span id="highlight-0" class="highlight">blood</span> vascular endothelium at single <span id="highlight-1" class="highlight">cell</span> resolution' | ||
expect(received).toBe(expected) | ||
@@ -572,3 +572,3 @@ }) | ||
const expected = | ||
'Pediatric non-red cell <span id="highlight-0" class="extra-bold">blood</span> product transfusion practices: what\'s the evidence to guide transfusion of the \'yellow\' blood products?' | ||
'Pediatric non-red cell <span id="highlight-0" class="highlight">blood</span> product transfusion practices: what\'s the evidence to guide transfusion of the \'yellow\' blood products?' | ||
expect(received).toBe(expected) | ||
@@ -575,0 +575,0 @@ }) |
{ | ||
"name": "js-solr-highlighter", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"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", |
@@ -19,3 +19,3 @@ # js-solr-highlighter | ||
var highlightedContent = highlightByQuery(query, content) | ||
// 'Platelet Volume Is Reduced In Metastasing Breast <span id="highlight-0" class="extra-bold">Cancer</span>: <span id="highlight-1" class="extra-bold">Blood</span> Profiles Reveal Significant Shifts.' | ||
// 'Platelet Volume Is Reduced In Metastasing Breast <span id="highlight-0" class="highlight">Cancer</span>: <span id="highlight-1" class="highlight">Blood</span> Profiles Reveal Significant Shifts.' | ||
``` | ||
@@ -28,3 +28,3 @@ ### With the validFields options that specify the fields valid in the query syntax. If not specified, all like x:x will be valid fields | ||
var highlightedContent = highlightByQuery(query, content, options) | ||
// 'A molecular map of lymph node <span id="highlight-0" class="extra-bold">blood</span> vascular endothelium at single cell resolution' | ||
// 'A molecular map of lymph node <span id="highlight-0" class="highlight">blood</span> vascular endothelium at single cell resolution' | ||
// "cell" will not be highlighted | ||
@@ -38,3 +38,3 @@ ``` | ||
var highlightedContent = highlightByQuery(query, content, options) | ||
// 'A molecular map of lymph node blood vascular endothelium at single <span id="highlight-0" class="extra-bold">cell</span> resolution' | ||
// 'A molecular map of lymph node blood vascular endothelium at single <span id="highlight-0" class="highlight">cell</span> resolution' | ||
// "blood" will not be highlighted | ||
@@ -46,10 +46,11 @@ ``` | ||
| ---- | ---- | ---- | | ||
| validFields | array | validFields are those parsed as fields. If undefined, all will be parsed as fields if they are like x:x | | ||
| highlightedFields | array | highlightedFields are those among validFields whose values will be highlighted. If undefined, the values of all valid fields will be highlighted | | ||
| highlightAll | boolean | highlightAll indicates whether to highlight all occurances of the text or the first found occurance only. Default is true | | ||
| validFields | array | validFields are those parsed as fields.<br />If undefined, all will be parsed as fields if they are like x:x | | ||
| highlightedFields | array | highlightedFields are those among validFields whose values will be highlighted.<br />If undefined, the values of all valid fields will be highlighted. | | ||
| highlightAll | boolean | highlightAll indicates whether to highlight all occurances of the text or the first found occurance only.<br />If undefined, it is true. | | ||
| highlightIdPattern | string | highlightIdPattern is the same pattern of the IDs associated with the highlights in the HTML.<br />A highlight ID consists of highlightIdPattern followed by the index of the highlight, such as "highlight-0", "highlight-1"...<br />If undefined, it is "highlight-" | | ||
| highlightClass | string | highlightClass is the classname of every highlight in the HTML. If undefined, it is "highlight" | | ||
## Highlighting rules | ||
TBA | ||
## Contact | ||
[Zhan Huang](mailto:z2hm@outlook.com "Zhan Huang") |
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
651875
932
53