projectEndings / staticSearch

A codebase to support a pure JSON search engine requiring no backend for any XHTML5 document collection
https://endings.uvic.ca/staticSearch/docs/index.html
Mozilla Public License 2.0
51 stars 22 forks source link

Make phrasal matching case-insensitive #304

Open martindholmes opened 6 months ago

martindholmes commented 6 months ago

The Moses project team have requested that phrasal matching be made case-insensitive. I believe this could be done with a single change to what is currently line 2032 of StaticSearch.js:

//Make the phrase into a regex for matching.
      let re = new RegExp(strRe);

becomes

//Make the phrase into a regex for matching.
      let re = new RegExp(strRe, "i");

I think this is a good idea, and I see no reason not to do it, although it may involve some fallout for tests, which might perhaps retrieve more hits for specific test phrases. @joeytakeda Do you agree we should just implement this for version 2.0 assuming there are no gotchas when we try it?

martindholmes commented 6 months ago

Actually it could be backported to 1.4 easily too. There will probably be documentation updates to do as well, though.

martindholmes commented 5 months ago

We introduced case-sensitivity on purpose in version 1.1, so that people could search for proper names:

"Phrasal searches are now case-sensitive, meaning that you can use a ‘phrasal search’ to search for proper names, by putting quotation marks around them and making the first letter upper-case."

I'd forgotten the history of this, but it's laid out in issue #104. That ticket ended with a comment from @joeytakeda:

I suppose we could make it configurable, but I'm hesitant to add more configuration options to the config. As far as I know, case sensitivity hasn't been an issue for any of the other projects, so I'm happy to just override the method for now unless it becomes clear that more projects want case insensitive phrasal searches.

And now we have one project which does. However, one project may not be enough to justify a new config item.

martindholmes commented 5 months ago

We decided to do an experimental implementation in a branch as follows:

martindholmes commented 5 months ago

This work will happen in the iss304-make-phrasal-search-case-sensitivity branch. (Screwed up the name, but meh.)

martindholmes commented 5 months ago

Basic working implementation now in iss304-make-phrasal-search-case-sensitivity branch. What remains to be done is tracking the checkbox's state in search history URLs. @joeytakeda I don't know if you were convinced of the usefulness of this, so you might want to try it out. One thing that's bugging me right now is that the auto-complete suggestions from the browser appear right where the checkbox and its label will appear and disappear, which means you don't necessarily see it right away when it appears.

martindholmes commented 5 months ago

Added the URL tracking bit. This is now functionally complete, but without any tests as yet.

martindholmes commented 5 months ago

@joeytakeda If you try this out and you think it's a good idea, I'll add tests and documentation before creating a PR. I purposely used the CSS visibility property rather than display because any end-user who doesn't want it to appear can keep it hidden with display: none.