christian-fei / Simple-Jekyll-Search

A JavaScript library to add search functionality to any Jekyll blog.
https://christian-fei.github.io/Simple-Jekyll-Search/
MIT License
1.34k stars 203 forks source link

Search by entire phrase? #182

Closed dzg closed 2 years ago

dzg commented 3 years ago

Is there any way to make this search for the entire input string, rather the words?

E.g., if I search for "let it roll", I get results for all posts which contain those 3 words, anywhere, in any order. I want to find posts which contain the actual string "let it roll".

dzg commented 3 years ago

I was able to accomplish this by changing src/SearchStrategies/LiteralSearchStrategy.js to

function LiteralSearchStrategy() {
   this.matches = function (str, crit) {
      if (!str) return false
      str = str.trim().toLowerCase()
      crit = crit.trim().toLowerCase()

      return str.indexOf(crit) >= 0
   }
}

but I would vote for having this be a search option.

Thanks! Awesome plugin!

dzg commented 3 years ago

... or instead of a flag, it could be triggered when the search input begins/ends with " ... like a Google search...

dzg commented 3 years ago

I just realized this was already implemented in 2df6280 but it hasn't been compiled to /dest yet