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

A JavaScript library for highlighting HTML text based on the query in the lucene/solr query syntax

  • 0.7.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
792
decreased by-16.54%
Maintainers
1
Weekly downloads
 
Created
Source

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 and text-annotator
The general highlighting process is:

  1. Derive which text to highlight from a query in the lucene syntax
  2. Highlight the derived text in the HTML

An example from Europe PMC

js-solr-highlighter has been used to highlight the article titles in the search results of Europe PMC. An example is https://europepmc.org/search?query=blood%20AND%20TITLE%3Acancer "an example from Europe PMC" "an example from Europe PMC"

Basic usage

No options

var query = 'cancer AND blood'
var content = 'Platelet Volume Is Reduced In Metastasing Breast Cancer: Blood Profiles Reveal Significant Shifts.'
var highlightedContent = highlightByQuery(query, content)
// '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.'

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 query = 'TITLE:blood AND CONTENT:cell'
var content = 'A molecular map of lymph node blood vascular endothelium at single cell resolution'
var options = { validFields: ['TITLE'] }
var highlightedContent = highlightByQuery(query, content, options)
// '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

With the highlightedFields options that specify the valid fields whose values will be highlighted. If not specified, the values of all valid fields will be highlighted

var query = 'TITLE:blood OR CONTENT:cell'
var content = 'A molecular map of lymph node blood vascular endothelium at single cell resolution'
var options = { validFields: ['TITLE', 'CONTENT'], highlightedFields: ['CONTENT'] }
var highlightedContent = highlightByQuery(query, content, options)
// '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

Options

FieldTypeDescription
validFieldsarrayvalidFields are those parsed as fields.
If undefined, all will be parsed as fields if they are like x:x
highlightedFieldsarrayhighlightedFields are those among validFields whose values will be highlighted.
If undefined, the values of all valid fields will be highlighted.
highlightAllbooleanhighlightAll indicates whether to highlight all occurances of the text or the first found occurance only.
If undefined, it is true.
highlightIdPatternstringhighlightIdPattern is the same pattern of the IDs associated with the highlights in the HTML.
A highlight ID consists of highlightIdPattern followed by the index of the highlight, such as "highlight-0", "highlight-1"...
If undefined, it is "highlight-".
highlightClassstringhighlightClass is the classname of every highlight in the HTML.
If undefined, it is "highlight".

Highlighting rules

Contact

Zhan Huang

Keywords

FAQs

Package last updated on 26 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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