Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-solr-highlighter

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-solr-highlighter - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

11

index.js

@@ -48,3 +48,5 @@ import TextAnnotator from 'text-annotator'

function highlightByQuery(query, content, options = {}) {
const { validFields, highlightedFields } = options
const { validFields, highlightAll, highlightedFields } = options
const searchFunc =
highlightAll === undefined || highlightAll ? 'searchAll' : 'search'

@@ -221,3 +223,3 @@ let words = []

words.forEach(word => {
const highlightIndexes = highlighter.searchAll(word, {
let res = highlighter[searchFunc](word, {
directSearchOptions: {

@@ -227,3 +229,4 @@ caseSensitive: false

})
highlightIndexes.forEach(highlightIndex => {
res = searchFunc === 'search' ? [res] : res
res.forEach(highlightIndex => {
const loc = highlighter.highlights[highlightIndex].loc

@@ -236,3 +239,3 @@ const text = highlighter.stripedHTML

}
// make sure we do not highlight part of a word
// make sure we do not highlight part of a word; can be moved up
const prevCharValid = loc[0] === 0 || fixVaild(text.charAt(loc[0] - 1))

@@ -239,0 +242,0 @@ const nextCharValid =

@@ -533,2 +533,14 @@ import { isStopWord, highlightByQuery } from './index.js'

})
test('blood', () => {
const query = 'blood'
const content =
"Pediatric non-red cell blood product transfusion practices: what's the evidence to guide transfusion of the 'yellow' blood products?"
const received = highlightByQuery(query, content, {
highlightAll: false
})
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?'
expect(received).toBe(expected)
})
})

@@ -535,0 +547,0 @@

{
"name": "js-solr-highlighter",
"version": "0.7.0",
"version": "0.7.1",
"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",

# js-solr-highlighter
A JavaScript library for highlighting HTML text based on the query in the lucene/solr query syntax
Run in the browser or Node.js environment
Built based on [lucene](https://github.com/bripkens/lucene "lucene") and [text-annotator](https://github.com/zhan-huang/text-annotator "text-annotator")
A JavaScript library for highlighting HTML text based on the query in the lucene/solr query syntax<br />
Run in the browser or Node.js environment<br />
Built based on [lucene](https://github.com/bripkens/lucene "lucene") and [text-annotator](https://github.com/zhan-huang/text-annotator "text-annotator")<br />
The general highlighting process is:

@@ -21,3 +21,3 @@ 1. Derive which text to highlight from a query in the lucene syntax

```
### With the validFields options that specify the fields valid in the query syntax. If not specified, all like X:X will be valid fields
### With the validFields options that specify the fields valid in the query syntax. If not specified, all like x:x will be valid fields
```javascript

@@ -42,6 +42,12 @@ var query = 'TITLE:blood AND CONTENT:cell'

## Options
| Field | Type | Description |
| ---- | ---- | ---- |
| 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 |
## Highlighting rules
TBA
## Contact
[Zhan Huang](mailto:z2hm@outlook.com "Zhan Huang")
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc