
Security News
Insecure Agents Podcast: Certified Patches, Supply Chain Security, and AI Agents
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.
query-text-match
Advanced tools
Calculates the matching score between query and text
yarn add query-text-match
const _ = require('lodash');
const queryTextMatch = require('./index');
const query = "because I can't you";
const texts = [
'The stranger officiates the meal.',
'When transplanting seedlings, candied teapots will make the task easier.',
'His mind was blown that there was nothing in space except space itself.',
"Please put on these earmuffs because I can't you hear.",
'Flash photography is best used in full sunlight.',
'It dawned on her that others could make her happier, but only she could make herself happy.',
'He was the type of guy who liked Christmas lights on his house in the middle of July.',
"Art doesn't have to be intentional.",
'It was getting dark, and we weren’t there yet.',
'He learned the important lesson that a picnic at the beach on a windy day is a bad idea.',
];
const results = texts.map((text) => ({ ...queryTextMatch(query, text), text }));
console.log(
JSON.stringify(
_.sortBy(results, [
'unmatchedQueryWordsCount',
'extraCharactersCount',
'totalDistance',
]),
null,
2
)
);
Outcome:
[
{
"matchedQueryWordsCount": 3,
"unmatchedQueryWordsCount": 1,
"queryWordsCount": 4,
"totalDistance": 6,
"extraCharactersCount": 0,
"takenWords": [
{
"index": 29,
"actualWord": "because",
"extraPerfixLength": 0,
"extraSufixLength": 0,
"UnNormalizedQueryWord": "because",
"normalizedQueryWord": "because",
"extraCharsLength": 0,
"taken": true,
"surroundingDistance": 7
},
{
"index": 37,
"actualWord": "I",
"extraPerfixLength": 0,
"extraSufixLength": 0,
"UnNormalizedQueryWord": "I",
"normalizedQueryWord": "i",
"extraCharsLength": 0,
"taken": true,
"surroundingDistance": 14
},
{
"index": 45,
"actualWord": "you",
"extraPerfixLength": 0,
"extraSufixLength": 0,
"UnNormalizedQueryWord": "you",
"normalizedQueryWord": "you",
"extraCharsLength": 0,
"taken": true,
"surroundingDistance": 7
}
],
"queryNormalizedWordsList": [
"because",
"i",
"cant",
"you"
],
"text": "Please put on these earmuffs because I can't you hear."
},
{
"matchedQueryWordsCount": 1,
"unmatchedQueryWordsCount": 3,
"queryWordsCount": 4,
"totalDistance": 0,
"extraCharactersCount": 0,
"takenWords": [
{
"index": 42,
"actualWord": "i",
"extraPerfixLength": 0,
"extraSufixLength": 0,
"UnNormalizedQueryWord": "i",
"normalizedQueryWord": "i",
"extraCharsLength": 0,
"taken": true
}
],
"queryNormalizedWordsList": [
"because",
"i",
"cant",
"you"
],
"text": "His mind was blown that there was nothing in space except space itself."
},
...
]
FAQs
Calculates the matching score between query and text
We found that query-text-match demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.

Security News
The planned feature introduces a review step before releases go live, following the Shai-Hulud attacks and a rocky migration off classic tokens that disrupted maintainer workflows.