Search made simple - SearchinGhostEASY

Hey - such an easy fix! Thats amazing, thank you for your support - and thank you for building such a useful tool for Ghost.

1 Like

OMG! This. Is. EVERYTHING.

Thank you! This is exactly what I was looking for and it is :star: :star: :star: :star: :star:

Here it is in action: https://www.womenconquerbiz.com/

I used the Set a menu search “icon” and even though I have a custom theme (thankfully) it worked PERFECTLY.

Thanks again! I’ve already shared it with a colleague who struggled with GhostHunter. And I’ll let others know as well.

Jen

1 Like

It is really simple to add it into website, but I have an issue on the Chinese searching, do you think is that possible can i tune it ?

1 Like

Hi,
How to add Russian (Cyrillic if I’m right) symbols to search?

Thank you forward.

Hello!

For any non-latin language, you have to add an extra configuration parameter. Please, refer to the underlying “searchinghost” documentation on Github.

For chinese only content, you can use this configuration:

{
  contentApiKey: '<your_api_key>',
  searchinghostOptions: {
    indexOptions: {
      encode: false,
      tokenize: function(str) {
        return str.replace(/[\x00-\x7F]/g, "").split("");
      }
    }
  }
}

For cyrillic only, that configuration:

{
  contentApiKey: '<your_api_key>',
  searchinghostOptions: {
    indexOptions: {
      encode: false,
      split: /\s+/
    }
  }
}

And if you want to use a mix of chinese/cyrillic + any latin language, you should go with:

{
  contentApiKey: '<your_api_key>',
  searchinghostOptions: {
    indexOptions: {
      split: /\s+/,
      encode: function (str) {
        var regexp_replacements = {
          "a": /[àáâãäå]/g,
          "e": /[èéêë]/g,
          "i": /[ìíîï]/g,
          "o": /[òóôõöő]/g,
          "u": /[ùúûüű]/g,
          "y": /[ýŷÿ]/g,
          "n": /ñ/g,
          "c": /[ç]/g,
          "s": /ß/g,
          " ": /[-/]/g,
          "": /['!"#$%&\\()\*+,-./:;<=>?@[\]^_`{|}~]/g,
          " ": /\s+/g,
        }
        str = str.toLowerCase();
        for (var key of Object.keys(regexp_replacements)) {
          str = str.replace(regexp_replacements[key], key);
        }
        return str === " " ? "" : str;
      }
    }
  }
}

I hope it will be clear enough to help you solve these issues.

2 Likes

Hi,

I am using SearchinGhostEASY with the code below at insert footer, it seems only latin & number works for the search, do you see am I missing anything here?

<script src="https://cdn.jsdelivr.net/gh/gmfmi/searchinghost-easy@latest/dist/searchinghost-easy-backpack.js"></script>
<script>
    new SearchinGhostEasy({
        contentApiKey: 'xxxxx',
        indexOptions: {
    split: /\s+/,
    encode: function(str) {
        var regexp_replacements = {
            "a": /[àáâãäå]/g,
            "e": /[èéêë]/g,
            "i": /[ìíîï]/g,
            "o": /[òóôõöő]/g,
            "u": /[ùúûüű]/g,
            "y": /[ýŷÿ]/g,
            "n": /ñ/g,
            "c": /[ç]/g,
            "s": /ß/g,
            " ": /[-/]/g,
            "": /['!"#$%&\\()\*+,-./:;<=>?@[\]^_`{|}~]/g,
            " ": /\s+/g,
        }
        str = str.toLowerCase();
        for (var key of Object.keys(regexp_replacements)) {
            str = str.replace(regexp_replacements[key], key);
        }
        return str === " " ? "" : str;
    }
},
    });
</script>

@yong, the “searchinghostOptions” object declaration is missing. Please copy/paste the following code:

<script src="https://cdn.jsdelivr.net/gh/gmfmi/searchinghost-easy@latest/dist/searchinghost-easy-backpack.js"></script>
<script>
    new SearchinGhostEasy({
        contentApiKey: 'xxxxx',
        searchinghostOptions: {
          indexOptions: {
            split: /\s+/,
            encode: function (str) {
              var regexp_replacements = {
                "a": /[àáâãäå]/g,
                "e": /[èéêë]/g,
                "i": /[ìíîï]/g,
                "o": /[òóôõöő]/g,
                "u": /[ùúûüű]/g,
                "y": /[ýŷÿ]/g,
                "n": /ñ/g,
                "c": /[ç]/g,
                "s": /ß/g,
                " ": /[-/]/g,
                "": /['!"#$%&\\()\*+,-./:;<=>?@[\]^_`{|}~]/g,
                " ": /\s+/g,
              }
              str = str.toLowerCase();
              for (var key of Object.keys(regexp_replacements)) {
                str = str.replace(regexp_replacements[key], key);
              }
              return str === " " ? "" : str;
            }
          }
        }
    });
</script>

Then, when you will do some testing, ensure to always use a “private nav” tab or to clear all the data stored for your website domain.

1 Like

Thank you! That was my bad, I was not attentive and didn’t saw that indexOptions was inside searchinghostOptions:

Thank you again!

Hello @gmfmi

Thank you for making our lives easier with this easy to install plugin! I have some questions and hope you can help me with it.

I am currently using

Ghost version - 4.47.1
Theme - Edition NEWSLETTER

  1. Does SearchinGhostEASY allow us to search by tags? For example, right now my blog only has 1 tag which is Google Cloud Platform. So when I search for Google Cloud Platform, it should show all the articles related to this tag? I tried to search by tags but it doesn’t seem to return all the article related to the tag.

  2. I also did this code injection at the Site Footer following your guide at https://github.com/gmfmi/searchinGhost#options

I have used version 1.1.2 which is the latest version as of now for consistency sake in the future.

<script src="https://cdn.jsdelivr.net/gh/gmfmi/searchinghost-easy@1.1.2/dist/searchinghost-easy-basic.js"></script>
<script>

    new SearchinGhostEasy({
        contentApiKey: '',
        searchinghostOptions: {
        template: function (post) {
   return `<a href="${post.url}">#${post.tags} - ${post.published_at} - ${post.title}</a>`
        }
        }

    });
</script>

When I tried to search, it show me this instead

It seems that it’s not able to index the post.tags? Not sure what I did wrong.

I did further testing by editing above code into below code, but still could not make it work. I suppose the default postsFields, postExtraFields and indexedFields have already included everything.

<script src="https://cdn.jsdelivr.net/gh/gmfmi/searchinghost-easy@1.1.2/dist/searchinghost-easy-basic.js"></script>
<script>

    new SearchinGhostEasy({
        contentApiKey: '',
        searchinghostOptions: {
        postsFields:['title', 'url', 'excerpt', 'custom_excerpt', 'published_at', 'feature_image'],
        postExtraFields: ['tags'],
        indexedFields: ['title', 'string_tags', 'excerpt', 'plaintext'],
        template: function (post) {
   return `<a href="${post.url}">#${post.tags} - ${post.published_at} - ${post.title}</a>`
        }
        }

    });
</script>

Hope you could help to clarify my doubts and thank you in advance!