Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Algolia as search provider #44

Closed
OlofHarrysson opened this issue Jan 17, 2021 · 6 comments
Closed

Add Algolia as search provider #44

OlofHarrysson opened this issue Jan 17, 2021 · 6 comments

Comments

@OlofHarrysson
Copy link

Hello,

I wish to use Algolia as a search provider for my website https://anyfig.docsforge.com/. It's responsive, powerful, and free for open source projects https://www.algolia.com/for-open-source/.

It seems to me that with the current search function, you can't find any text on the website as it is limited to headings and pages (could be wrong here). Algolia is better in that respect since you can search and find specific words. To see the search in action, you can test it on my previous website https://anyfig.now.sh/

I was hoping that it could be an opt-in via the configuration file

@erez-o
Copy link
Owner

erez-o commented Jan 17, 2021

Hi,

I think you need to apply as an open source project first at https://docsearch.algolia.com/

Regarding integration in docsforge, I did some testing and the following method worked for me.

I followed the guideline at https://docsearch.algolia.com/docs/dropdown

You can add custom JS and CSS into docsforge, by editing project settings (cog icon, https://anyfig.docsforge.com/admin/edit-project-settings/)

Add the following CSS:

<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/docsearch.js@v2.6.3/dist/cdn/docsearch.min.css"
/>

Add the following JS: (I tried algolia example test project)

<script src="https://cdn.jsdelivr.net/npm/docsearch.js@v2.6.3/dist/cdn/docsearch.min.js"></script>
<script>
  docsearch({
    apiKey: '25626fae796133dc1e734c6bcaaeac3c',
    indexName: 'docsearch',
    inputSelector: '#search-in-project',
    debug: false,
  });
</script>

I have however no experience with optimizing algolia's search output (crawler + scraper), so let me know how well it works.

@erez-o
Copy link
Owner

erez-o commented Jan 19, 2021

I can see at https://anyfig.docsforge.com/ that the old search is still visible. I'll have an option to disable it on my next release.

I do see however that algolia search results link to pages in https://anyfig.now.sh/ website. Can that be changed?

@OlofHarrysson
Copy link
Author

OlofHarrysson commented Jan 25, 2021

Hi, thanks for helping out! I tried the method that you suggested and it seems to be working, but as you said - the links go to the old website. Algolia fixes this manually by configuring their crawler https://github.com/algolia/docsearch-configs/blob/master/configs/anyfig.json.

That configuration file should also contain options to get the search functionality working well/optimized. I'm still waiting for Algolia to get back to me. Once they do and we've made the necessary changes I'll write here again :)

I'll have an option to disable it on my next release.

Great!

@erez-o
Copy link
Owner

erez-o commented Feb 3, 2021

Fixed, you can now disable the default search in your project settings. I've added a short help section in https://help.docsforge.com/master/search-engines/ .

Tell me if their crawler behaves well, and if it doesn't, maybe I can help. Leaving issue open for now.

@OlofHarrysson
Copy link
Author

Works great! Unfortunately, Algolia hasn't replied to my emails about reconfiguring the crawler. I'm not sure why but I want to believe that they're just overloaded. I'm not in a rush so it's ok.

I'll ping you if I run into problems with the crawler, thanks for offering :)

@OlofHarrysson
Copy link
Author

OlofHarrysson commented Feb 9, 2021

Hello, I've managed to add the Algolia search for the docsforge website with the help from Algolia. We changed the config in their gir repo. This new config supports both the old anyfig-website as well as the new docsforge one.

It seems to be working well, I can search for text in the tutorial as well as the API. I'm quite happy with the result - just want to flag that it won't support multiple versions the way it's set up now. Algolia can crawl different versions and it's up to the user to separate the versions/tags they want to show to the user. This is described in their docs

I changed the inserted javascript on the docsforge website to include the facetFilters

<script src="https://cdn.jsdelivr.net/npm/docsearch.js@v2.6.3/dist/cdn/docsearch.min.js"></script>
<script>
  docsearch({
    apiKey: 'real-api-key',
    indexName: 'anyfig',
    inputSelector: '#search-in-project',
    debug: false,
    algoliaOptions: {
        'facetFilters': ["tags:docsforge", "version:master"]
    },
  });
</script>

This makes it so that I only get results for the tags:docsforge and version:master. If one needs to support search for more versions, the master version can't be hardcoded. I suppose inserting different javascript on different versions of the website would solve this but I'm OK with just one version at the moment :)

I'm closing the issue, thanks for the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants