Search for Ghost

I built search with Google Custom Search, but I used the API. I use React as a front end, and the Ghost Content API. I get search results for my domain from Google, and let React parse it. This way I can style the search results as I please. Check it out, https://www.theportlandpour.com/. I’ll post a case study on how I built it next week, but I’m pretty happy with the results.

3 Likes

I was planning to take the same approach for search on my new blog (Google custom search API). You did a great job with yours!

If you would be willing to share a case study or some quick tips that would great! The Google side is easy, but I haven’t explored yet how to get the additional info re. my posts. Are you using the API to get featured images, etc. for the posts / pages that Google returns?

If I can’t find a Search option on a Website, I still use the following within the URL line: “site http://example.tld searchword” (without the quotation marks of course) and after hitting Enter I mostly get what I want. :-)

I know it’s not an elegant Solution but it works. Maybe it would be possible to pack this “Function” into a little Script or behind a Link on the actual Website to make it work like a good Search Function?!

1 Like

I have built a solution which we use on our blog at ciserro.com/blog, which i have shared as a gist. since we don’t use the frontend of ghost in our webapp (written in React), integrating this with your ghost installation is up to you, but this is a solution anyone can use with self hosting.

It uses elastic-lunr.js and @tryghost/content-api to provide a search api for ghost. it also provides an Archive feature which allows you to browse posts by month/year. This module exports 3 functions start,search, and archive. search and archive should be setup as express routes, while start should be used to start the search index. you will need to add your ghost credentials in the file before starting it. license is MIT, free to all to use and modify, no attribution needed.

gist: Search + Archive Implementation for a Ghost Blog · GitHub

note: you will need to install the dependencies before using. they are elastic-lunr and @tryghost/content-api.

best of luck,
Garrett Morris

Thanks! I haven’t forgotten about this. I’m finishing the case study this week, but adding some detail. I’ll post the link here when it’s done, but, tldr: set up Google Custom Search, use the REST API to make the request, when you get the response, parse the links for slugs. With an array of slugs, request the content from the Ghost Content API, and display as you see fit. Also, don’t forget to update state with the search page number. IIRC, Google only returns 10 links per request.

Makes sense! Should be reasonably straightforward.

Thank you for your willingness to share more detail when you are able!

Chris

I wrote an article on Medium about this. Here’s how I added Google Custom Search to The Portland Pour. @cmckulka Adding Google Custom Search to a headless Ghost blog with a React/Redux front end | by Tony M | Medium

@tonym but WHY on medium.com?

1 Like

Why not?

Great article!! Will definitely be leveraging your lessons learned as I integrate search into my site!

Thank you for offering this to the community.

Chris

@tonym because you are kinda locked in at medium.com

I came across GhostFinder and it’s very elegant, using the Ghost2.0 Content API

https://electronthemes.com/blog/add-search-option-to-ghost-theme/

2 Likes

Hi, sorry if I answer you just now, I wanted to send you updated links to the algolia code, unfortunately I can’t.
I was also flagged by the community without an apparent reason

Hi, I quickly integrated ElasticSearch with Ghost to provide an enhanced search service on my blog without modifying any line of code in Ghost.

Bellow how I did :

Sorry, the post is in french ;-)

6 Likes

How is Ghost coming along with this? It is still a frustration, not having this as a basic feature in Ghost without needing to do too much development to add a custom search. The built-in search in the admin console which searches posts works marvelous. Just move that to the public side of the platform? (I know, it is probably harder than what I believe it to be :slight_smile: )

I have tried that ghost-search plugin you mention, but i had to switch to ghosthunter. Even when i had an issue with it the ghost-search, the creator/mantainer answer was: Switch to ghost hunter.

Is it not possible to just use the ContentAPI and filter results by whatever the search term is??

I think that’s what GhostHunter actually does

Seems a little bit a faster answer.
Yes GhostHunter can be one solution to search content in Ghost using APIv2.

But No it isn’t a built-in search solution (because use an external product) and seems a little bit fat with > 100KB, using client browser side and not compatible with all double bit characters (like Japanese, Chinese etc).

I think it’s for that many Ghost’s users ask about a real built-in search engine into Ghost himself, and seems waiting a long because flag in this post has been changed to “planned” for a while.

The JavaScript in the library can be added to the Ghost theme itself, no external product needed. The library also uses lunr.js which appears to have good language support Language Support : Lunr

1 Like