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!

today this has helped me again with the insert an icon into nav menu feature. thanks @gmfmi for your contribution and continued work. merci

Hey @cmy113,

You code sample is close to something that work. You issue is the “tags” element is an array of objects. Here is how it looks like in your case:

[{id: "626542270e81830001dfac57", name: "Google Cloud Platform", slug: "google-cloud-platform", 
}]

To display the 1st tag’s name, you can for example, use ${post.tags[0].name}.

Hope it will help you.

Hi,

great package, thanks!

Just one question: Is there a way to self host your script? Even if i self-host https://cdn.jsdelivr.net/gh/gmfmi/searchinghost-easy@latest/dist/searchinghost-easy-backpack.js , this one will load another .js file from jsdelivr.

Hi @marius1!

Sure, you can totally self-host this script and it will automatically load the 2nd one from JSdelivr. A better option would be to host both the “easy” and the “search” scripts. This way you do not rely on any CDN.

Please note that this plugin is no longer maintained as Ghost V5 natively support a search feature. If you are not on the V5 yet, you should probably consider the migration (if possible).

Hi there,

is there any chance I can realize this use case with this SearchinGhost:

Show only search results from the current logged-in user’s tier

Context: I want users to be able to search only for posts of their actual tier. Posts from other tiers shouldn’t come up in the search results at all (really, I want to hide them!).

Besides having the posts’ access restricted to the tiers, I additionally have all posts marked with a special tag (tier1, tier2, tier3, 
).

If user1 (subscribed to tier1) now hits the search button, I want her to see only search results for posts that have the tag #tier1.

Thanks in advance and best regards

This is possible, but it would require theme customization.

I figured out that this here could solve my use case:

searchOptions: {
    where: {
        string_tags: "tag1"
    }
}

I will offer the search form only on specific pages. Since all my pages have a url like 
com/tag_name/
, I’d like to dynamically include that “tag_name” in the above mentioned search options, so:

searchOptions: {
    where: {
        string_tags: "{{dynamic_tag_name_of_current_page}}"
    }
}

Does anybody know how I can get this info?

I’m assuming this is built into the theme. (It won’t work as code injection.)

You can use {{page.slug}} or {{slug}} if you’re already in the page context.

Yeah, thought the same, but both didn’t work. :thinking:

It’d be helpful to see the code of the page. :)

Sure:

Of course, this isn’t nice code
I’m still testing, if this search function is doing the job. As soon as I got this slug-thing solved, I’ll adjust code placement.