Search for Ghost

👍🏼-planned
#12

I agree. Thanks for the tip, will check it out.

The issue that I have is this: I have a team of young students who wants to help me start blogging and writing for students and teenagers. I am the only one that can get something installed and set up but I am by no means a developer. So struggled to get Ghost up and running, now that it is done, great stuff! But then someone asked me: how do people search for specific questions etc that we will cover one a blog page just full of posts and I was like “oh yeah good question”.

I know Ghost has come a long way, but if they want more users to switch over to Ghost and focus more on writing…it seems you spend more time trying to get everything up and going and developing that writing.

Yes Ghost Pro solves many of that, but Ghost Pro does not have search either and it is expensive.

So I am glad to see it is planned, but would have thought it is a core feature from earlier on.

2 Likes
#13

ElasticSearch support would be dope in the future.

#14

just an idea.

use sqlite3 as database for your ghost.
then there will be a database file.
open the database file via sqlite3.

$sqlite3 content/data/ghost-dev.db
SQLite version 3.11.0 2016-02-15 17:29:24
Enter “.help” for usage hints.
sqlite> .tables
accesstokens migrations refreshtokens
api_keys migrations_lock roles
app_fields mobiledoc_revisions roles_users
app_settings permissions sessions
apps permissions_apps settings
brute permissions_roles subscribers
client_trusted_domains permissions_users tags
clients posts users
integrations posts_authors webhooks
invites posts_tags

As you can see, all posts definitely stored in the table named ‘posts’.

sqlite> select * from posts;
id|uuid|title|slug|mobiledoc|html|comment_id|plaintext|feature_image|featured|page|status|locale|visibility|meta_title|meta_description|author_id|created_at|created_by|updated_at|updated_by|published_at|published_by|custom_excerpt|codeinjection_head|codeinjection_foot|og_image|og_title|og_description|twitter_image|twitter_title|twitter_description|custom_template

Then we got the structure of the ‘posts’ table.
As I tested, ‘slug’ is the route path of a recorded post.

let’s search posts contains ‘welcome’ as an example.
sqlite> select slug from posts where html like ‘%welcome%’;
slug
apps-integrations
welcome

then we can check the real post in browser.
http://localhost:2368/welcome
http://localhost:2368/apps-integrations

see, search things goes well in a shell bash.
all we need to do write js codes to do above operations and display the result correctly in ghost core server module.

anyone who familiar with ghost developing work can have a try for that.
any suggestion please guide.
I would like to implement it at part time.
Hope I can finish it soon.

1 Like
#15

i just realised that the Ghost already has the search built in into the admin console, why not just enable that feature in the main theme too.

4 Likes
#16

Yes. I too agree. Basic post search should be provided by Ghost natively. Many themes from Ghost Marketplace like Voice support search functionality but nothing beats native support. I guess with Ghost Content API now public, providing a basic search functionality shouldn’t be a hard task for the people at GHOST. Please guys, we need it!

1 Like
#17

Hi folks, I’m currently considering migrating from WP to Ghost, I publish a long running blog with 60,000+ articles and our readers use search a lot to discover our back catalogue. Is Algolia still experimental/unreliable?

#18

docs.ghost.org is powered by Algolia so I assume it’s reliable to use.

1 Like
#19

Hello,
I also use Algolia, and I feel really good, this is the address if you want to see it

Warning I use adsense NOT profiled.

3 Likes
#20

Can you provide more info on how you integrated Algolia search with Ghost?

There is a way here, but it seems outdated:

I checked https://docs.ghost.org/integrations/, but I saw no integration (maybe Ghost team can help with this?).

2 Likes
#21

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
#23

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?

#24

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. :slight_smile:

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
#25

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: https://gist.github.com/r3wt/fbaf844a9864e1d101fdb08e345853f2

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

best of luck,
Garrett Morris

#26

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.

#27

Makes sense! Should be reasonably straightforward.

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

Chris

#28

I wrote an article on Medium about this. Here’s how I added Google Custom Search to The Portland Pour. @cmckulka https://medium.com/@tony.m.pdx/adding-google-custom-search-to-a-headless-ghost-blog-with-a-react-redux-front-end-b8b79b6dfff7

#29

@tonym but WHY on medium.com?

#30

Why not?

#31

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

#32

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