vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
11.48k stars 1.86k forks source link

Algolia search is broken #1970

Closed baumannzone closed 1 year ago

baumannzone commented 1 year ago

Describe the bug

I am experiencing an issue with the integrated search component (Algolia). The search function is not working properly, as it returns zero results when I use the web interface in my recently created project with Vitepress.

However, if I perform a search using the API or on Algolia's website, the search function works correctly and returns results.

It's possible that there may be an issue with the search component in Vitepress that's causing this problem.

I wanted to bring this to your attention in the hopes that it can be addressed and fixed as soon as possible.

Reproduction

image

Expected behavior

Show results after searching

System Info

System:
    OS: macOS 13.2.1
    CPU: (8) x64 Apple M1
    Memory: 7.73 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
  Browsers:
    Brave Browser: 107.1.45.133
    Chrome: 109.0.5414.119
    Chrome Canary: 112.0.5609.0
    Firefox: 95.0.2
    Firefox Developer Edition: 108.0
    Safari: 16.3

Additional context

UI Request:

https://5d6frgc6t9-dsn.algolia.net/1/indexes/*/queries?x-algolia-agent=Algolia%20for%20JavaScript%20(4.8.5)%3B%20Browser%20(lite)%3B%20docsearch%20(3.3.3)%3B%20docsearch-react%20(3.3.3)%3B%20docsearch.js%20(3.3.3)&x-algolia-api-key=e04451b589c484090xxxxxxxxxxxxxxx&x-algolia-application-id=5D6FRGxxxx

Request Method: POST Status Code: 200 OK

image

API Request (Node.js) image

{
  hits: [
    {
      title: 'Pill 2 AWS',
      description: 'Create a new AWS project from the command line',
      tags: [Array],
      objectID: '85344354000',
      _highlightResult: [Object]
    }
  ],
  nbHits: 1,
  page: 0,
  nbPages: 1,
  hitsPerPage: 20,
  exhaustiveNbHits: true,
  exhaustiveTypo: true,
  exhaustive: { nbHits: true, typo: true },
  query: 'AWS',
  params: 'query=AWS',
  renderingContent: {},
  processingTimeMS: 1,
  processingTimingsMS: {
    getIdx: { load: [Object], total: 1 },
    request: { roundTrip: 30 },
    total: 1
  },
  serverTimeMS: 1
}

Validations

baumannzone commented 1 year ago

Please let me know if there is any further information or details I can provide to assist with troubleshooting this issue."

brc-dd commented 1 year ago

your index needs the lang information too as we are filtering based on that

baumannzone commented 1 year ago

Hi, @brc-dd! Thanks for your reply. Where should I put that lang key and what values does it accept, any link to the doc?

My question is, why does it work through the API?

brc-dd commented 1 year ago

I'm not sure how you're creating that index, but if you'd run algolia's crawler it would've indexed the html lang attribute too.

It's working through the API because you haven't specified facetFilters: ['lang:en-US'] in your request.

baumannzone commented 1 year ago

Im using the free quote, I don't have access to the crawler. I'm completely new to Algolia, I may be missing something (?)

brc-dd commented 1 year ago

Just a clarification on our side: we only support https://docsearch.algolia.com/ (docsearch is free for open-source libraries). If that's the case for you, then you can use https://crawler.algolia.com/admin/ to access crawler configuration.

If that's not the case, then you will need to build your own search component or use any of the ones mentioned at #670

baumannzone commented 1 year ago

Thanks for your clarification. It's a public repo and it's open source. Here is the website and this is the repo.

So if I'm not wrong, I should have access to the algolia crawler, right?

brc-dd commented 1 year ago

Yeah, you should have, can you try logging in that admin dashboard?

baumannzone commented 1 year ago

Thank you. Actually, I dont have access. But it looks like an auth error. I will try later.

brc-dd commented 1 year ago

If it's a blocker than try downgrading to vitepress@1.0.0-alpha.36 or older. Those versions should work. Or you can also patch vitepress to delete this line:

https://github.com/vuejs/vitepress/blob/e8e87215aceb80c8275985aeb40062641d30b626/src/client/theme-default/components/VPAlgoliaSearchBox.vue#L39

baumannzone commented 1 year ago

I just requested access to the crawler. It seems to be that was the problem. If that doesn't solve my problem, I'll be creating a custom search component. Let's keep this issue open until I figure out what's going on.

As feedback, I think Vitepress docs should provide more context about how Algolia should work.

MarkusKeck commented 1 year ago

If you really need a fast solution and you need the newest vitepress version you can try vitepress-plugin-search. It is an offline search so you dont need to register anything, in the meantime you can try to configure angolia.

//vite.config.ts
import { SearchPlugin } from "vitepress-plugin-search";
import { defineConfig } from "vite";

//default options
var options = {
  ...flexSearchIndexOptions,
  previewLength: 62,
  buttonLabel: "Search",
  placeholder: "Search docs",
};

export default defineConfig({
  plugins: [SearchPlugin(options)],
});
brc-dd commented 1 year ago

As feedback, I think Vitepress docs should provide more context about how Algolia should work.

Yeah, the docs are missing many things. I agree that it's sort of ironic considering we are building a docs-centered framework 😅. But yeah we will update that with an official crawler config and hopefully support for local search as well.

After you get access, try adding attributesForFaceting (ref. https://github.com/vuejs/vitepress/issues/1935#issuecomment-1433765099)

baumannzone commented 1 year ago

Thank you very mucho, amigo. I'll let you know how it goes.

@MarkusKeck I want to try using the default search component, I'll try your solution if I can't get it to work.

baumannzone commented 1 year ago

I just got a message, it says my site won't be accepted bcs is under construction and has tons of lorem ipsums text. But I think when I finish creating the website, I will be given access to the tool.

brc-dd commented 1 year ago

Let's move this to discussion. If there is any issue you need some help you can directly post in our discord too.