vitepress: Algolia search is broken

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

  • Create an Algolia account
  • Configure the algolia section with index, API key and app id.
    •   appId: '5D6FRGxxxx',  
        apiKey: 'e04451b589c484090xxxxxxxxxxxxxxx',  
        indexName: 'csspills'
      
  • Create the index (both manually / via API)
    • [
        {
          title: 'Pill 1 CLI',
          description: 'Create a new project with the CLI',
          tags: [ 'demo1', 'cli' ]
        },
        {
          title: 'Pill 2 AWS',
          description: 'Create a new AWS project from the command line',
          tags: [ 'demo2', 'AWS' ]
        }
      ]
      
  • Start the local server
  • Search

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

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

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)

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)],
});

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

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

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