hasura / gatsby-gitbook-starter

Generate GitBook style modern docs/tutorial websites using Gatsby + MDX
https://hasura.io/learn/graphql/react/introduction/
MIT License
985 stars 376 forks source link

add search functionality #6

Closed praveenweb closed 5 years ago

praveenweb commented 5 years ago

The search should crawl through all the markdown files for content and give back the links to the pages of the content with possible highlighting of the searched word.

coco98 commented 5 years ago

Or maybe have an algolia integration?

On Thu, Jul 25 2019 at 11:17 AM, Tirumarai Selvan < notifications@github.com > wrote:

The search should crawl through all the markdown files for content and give back the links to the pages of the content with possible highlighting of the searched word.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub ( https://github.com/hasura/gatsby-gitbook-starter/issues/6?email_source=notifications&email_token=AABAAWACSDNNIKW7EJAMF4LQBE45TA5CNFSM4IGXDSD2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HBMPAJQ ) , or mute the thread ( https://github.com/notifications/unsubscribe-auth/AABAAWGDMRI2TR2F37UAJOLQBE45TANCNFSM4IGXDSDQ ).

elijah-io commented 5 years ago

On Line 19 of the config.js file, you have:

"indexName": "",

What is an example of what needs to go here? I'm having trouble figuring it out from Algolia's docs.

Thanks in advance for any assistance (and for creating and maintaining this project).

elijah-io commented 5 years ago

Of course I figured it out right after posting this. For anyone in the future: you have to create the searchable index on Algolia's end first, then use the name of the index you created in your config.

elijah-io commented 5 years ago

I apologize for the spam, but I did enounter another issue that I'm sure has to do with my Algolia configuration, but I can't seem to figure it out.

Search Error

I haven't modified anything in src/utils/algolia.js but I'm thinking maybe I need to? Or perhaps I need to add searchable attributes on Algolia's end, but it says it can't find them when I add them. I also wonder if maybe I need to deploy this to have it work (rather than just locally).

praveenweb commented 5 years ago

@elijah-io You don’t need to modify any code to get the Algolia search working. If the configuration is set correctly, all you need to do is to do a ‘npm run build’ once with the correct environment variables set and indexing should happen automatically. Have you tried running that step or is the index you are trying to use is different?

elijah-io commented 5 years ago

I had to setup my own index first to get it working, otherwise I was getting a different error and the app wouldn't build at all (saying that index was null). But yes, I did run npm run build with the correct environmental variables and that's how I hit that initial issue I worked through by creating the index on Algolia's end.

elijah-io commented 5 years ago
Screen Shot 2019-08-28 at 2 21 55 PM

Is this where I am going wrong?

Screen Shot 2019-08-28 at 2 22 08 PM

As you can see, this is the index I am targeting, but it isn't seeing any data come through the API. I haven't modified anything else other than point it to the right index.

theBliz commented 5 years ago

@elijah-io did you close the issue because you were able to solve this? I'm having the same issue but probably I'm doing something wrong. How did you solve it?

theBliz commented 5 years ago

Nevermind. I figured it out. Basically you need to do npm run build in order to set the index in algolia and then you can use it also locally. Might be cleared out in the readme, if I have time I'll make a pull request

theBliz commented 5 years ago

@praveenweb I've added a small section to quickly explain the steps needed for running algolia the first time. You can find it here https://github.com/hasura/gatsby-gitbook-starter/pull/43