Skip to content

Commit

Permalink
Merge pull request #3 from neilboyd/exact-search
Browse files Browse the repository at this point in the history
exact search with quotes
  • Loading branch information
neilboyd authored Jul 18, 2024
2 parents 8207606 + bb39886 commit f9bc704
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Simple-Jekyll-Search
on: [push]
jobs:
build_deploy:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@master
with:
Expand All @@ -26,4 +26,4 @@ jobs:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
npm config set '//registry.npmjs.org/:_authToken' "${{ secrets.NPM_TOKEN }}"
npm publish || true
npm publish
12 changes: 11 additions & 1 deletion dest/simple-jekyll-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,17 @@ function LiteralSearchStrategy () {
this.matches = function (str, crit) {
if (!str) return false
str = str.trim().toLowerCase()
crit = crit.endsWith(' ') ? [crit.toLowerCase()] : crit.trim().toLowerCase().split(' ')

let exact = false
if (crit.endsWith(' ')) {
exact = true
}
if (crit.startsWith('"') && crit.endsWith('"')) {
exact = true
crit = crit.substring(1, crit.length - 2)
}
crit = crit.toLowerCase()
crit = exact ? [crit] : crit.split(' ')

return crit.filter(word => str.indexOf(word) >= 0).length === crit.length
}
Expand Down
2 changes: 1 addition & 1 deletion dest/simple-jekyll-search.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion example/js/simple-jekyll-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,17 @@ function LiteralSearchStrategy () {
this.matches = function (str, crit) {
if (!str) return false
str = str.trim().toLowerCase()
crit = crit.endsWith(' ') ? [crit.toLowerCase()] : crit.trim().toLowerCase().split(' ')

let exact = false
if (crit.endsWith(' ')) {
exact = true
}
if (crit.startsWith('"') && crit.endsWith('"')) {
exact = true
crit = crit.substring(1, crit.length - 2)
}
crit = crit.toLowerCase()
crit = exact ? [crit] : crit.split(' ')

return crit.filter(word => str.indexOf(word) >= 0).length === crit.length
}
Expand Down
2 changes: 1 addition & 1 deletion example/js/simple-jekyll-search.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-jekyll-search",
"version": "1.10.0",
"version": "1.11.0",
"description": "Simple Jekyll site search using javascript and json",
"main": "dest/simple-jekyll-search.js",
"scripts": {
Expand Down
12 changes: 11 additions & 1 deletion src/SearchStrategies/LiteralSearchStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ function LiteralSearchStrategy () {
this.matches = function (str, crit) {
if (!str) return false
str = str.trim().toLowerCase()
crit = crit.endsWith(' ') ? [crit.toLowerCase()] : crit.trim().toLowerCase().split(' ')

let exact = false
if (crit.endsWith(' ')) {
exact = true
}
if (crit.startsWith('"') && crit.endsWith('"')) {
exact = true
crit = crit.substring(1, crit.length - 2)
}
crit = crit.toLowerCase()
crit = exact ? [crit] : crit.split(' ')

return crit.filter(word => str.indexOf(word) >= 0).length === crit.length
}
Expand Down
Loading

0 comments on commit f9bc704

Please sign in to comment.