kubesphere / website

KubeSphere website and documentation
https://kubesphere.io
Apache License 2.0
80 stars 293 forks source link

Optimize docs search results #3141

Closed zheng1 closed 2 months ago

zheng1 commented 2 months ago

Issue details:

Now when we search in a document, the return value may contain a different version of the current document. This can be very confusing for the user.

Details

截屏2024-07-11 14 53 15

Expected behavior: When searching in a 3.4 document, only 3.4 document results will be returned, not other versions of the document.

Possible Solution:

  1. add the version number to the document's hugo template.
  2. add a website, kubesphere.io, to your agolia crawler account.
  3. modify the configuration of the agolia crawler website
  4. modify the docsearch configuration

Related Sites: https://crawler.algolia.com/ https://gohugo.io/templates/

Related configurations:

Details

```yaml new Crawler({ appId: "P64S7K7Q7W", apiKey: "sssssssssssssssss", rateLimit: 8, startUrls: [ "https://www.kubesphere.io/zh/docs/", "https://www.kubesphere.io/", "https://www.kubesphere.io/docs/", ], sitemaps: ["https://www.kubesphere.io/sitemap.xml"], renderJavaScript: true, exclusionPatterns: [ "https://www.kubesphere.io/zh/docs/v4.1/", "https://www.kubesphere.io/docs/v4.1/", ], ignoreCanonicalTo: true, discoveryPatterns: ["https://www.kubesphere.io/**"], schedule: "every 24 hours", actions: [ { indexName: "kubesphere", pathsToMatch: ["https://www.kubesphere.io/zh/docs/**"], recordExtractor: ({ $, helpers }) => { return helpers.docsearch({ recordProps: { lvl1: ".md-body h2", content: ".md-body p, .md-body li", lvl0: { selectors: ".md-body h1", }, lvl2: ".md-body h3", lvl3: ".md-body h4", lvl4: ".md-body h5", lvl5: ".md-body h6", lang: { defaultValue: ["zh"], }, }, indexHeadings: true, }); }, }, { indexName: "kubesphere", pathsToMatch: ["https://www.kubesphere.io/docs/**"], recordExtractor: ({ $, helpers }) => { return helpers.docsearch({ recordProps: { lvl1: ".md-body h2", content: ".md-body p, .md-body li", lvl0: { selectors: ".md-body h1", }, lvl2: ".md-body h3", lvl3: ".md-body h4", lvl4: ".md-body h5", lvl5: ".md-body h6", lang: { defaultValue: ["en"], }, }, indexHeadings: true, }); }, }, ], initialIndexSettings: { kubesphere: { attributesForFaceting: ["type", "lang"], attributesToRetrieve: ["hierarchy", "content", "anchor", "url"], attributesToHighlight: ["hierarchy", "hierarchy_camel", "content"], attributesToSnippet: ["content:10"], camelCaseAttributes: ["hierarchy", "hierarchy_radio", "content"], searchableAttributes: [ "unordered(hierarchy_radio_camel.lvl0)", "unordered(hierarchy_radio.lvl0)", "unordered(hierarchy_radio_camel.lvl1)", "unordered(hierarchy_radio.lvl1)", "unordered(hierarchy_radio_camel.lvl2)", "unordered(hierarchy_radio.lvl2)", "unordered(hierarchy_radio_camel.lvl3)", "unordered(hierarchy_radio.lvl3)", "unordered(hierarchy_radio_camel.lvl4)", "unordered(hierarchy_radio.lvl4)", "unordered(hierarchy_radio_camel.lvl5)", "unordered(hierarchy_radio.lvl5)", "unordered(hierarchy_radio_camel.lvl6)", "unordered(hierarchy_radio.lvl6)", "unordered(hierarchy_camel.lvl0)", "unordered(hierarchy.lvl0)", "unordered(hierarchy_camel.lvl1)", "unordered(hierarchy.lvl1)", "unordered(hierarchy_camel.lvl2)", "unordered(hierarchy.lvl2)", "unordered(hierarchy_camel.lvl3)", "unordered(hierarchy.lvl3)", "unordered(hierarchy_camel.lvl4)", "unordered(hierarchy.lvl4)", "unordered(hierarchy_camel.lvl5)", "unordered(hierarchy.lvl5)", "unordered(hierarchy_camel.lvl6)", "unordered(hierarchy.lvl6)", "content", ], distinct: true, attributeForDistinct: "url", customRanking: [ "desc(weight.pageRank)", "desc(weight.level)", "asc(weight.position)", ], ranking: [ "words", "filters", "typo", "attribute", "proximity", "exact", "custom", ], highlightPreTag: '', highlightPostTag: "", minWordSizefor1Typo: 3, minWordSizefor2Typos: 7, allowTyposOnNumericTokens: false, minProximity: 1, ignorePlurals: true, advancedSyntax: true, attributeCriteriaComputedByMinProximity: true, removeWordsIfNoResults: "allOptional", }, }, }); ```