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

fix: DocSearch-Hit-source is empty in certain cases #2295

Closed
wants to merge 1 commit into from

Conversation

brc-dd
Copy link
Contributor

@brc-dd brc-dd commented Aug 15, 2024

fixes #2294

Earlier hit.hierarchy.lvl0 was returned only if hit._highlightResult is falsy. But in certain cases hit._highlightResult.hierarchy is not there even if hit._highlightResult is present. This PR returns hit.hierarchy.lvl0 as a fallback always.

I'm not sure, but some change in Algolia's response triggered this. Earlier it was working fine. The types still indicate that hit._highlightResult.hierarchy.lvl0.value will always be set. So, it might be regression in some other service and other parts might also break 👀

interface DocSearchHitHighlightResult {
content: DocSearchHitAttributeHighlightResult;
hierarchy: DocSearchHitHighlightResultHierarchy;
hierarchy_camel: DocSearchHitHighlightResultHierarchy[];
}

image

PS: the original issue didn't share the crawler config. Here it is:

Expand
new Crawler({
  appId: "8J64VVRP8K",
  apiKey: "---",
  rateLimit: 8,
  startUrls: ["https://vitepress.dev/"],
  renderJavaScript: false,
  sitemaps: [],
  exclusionPatterns: [],
  ignoreCanonicalTo: false,
  discoveryPatterns: ["https://vitepress.dev/**"],
  schedule: "at 05:10 on Saturday",
  actions: [
    {
      indexName: "vitepress",
      pathsToMatch: ["https://vitepress.dev/**"],
      recordExtractor: ({ $, helpers }) => {
        return helpers.docsearch({
          recordProps: {
            lvl1: ".content h1",
            content: ".content p, .content li",
            lvl0: {
              selectors: "",
              defaultValue: "Documentation",
            },
            lvl2: ".content h2",
            lvl3: ".content h3",
            lvl4: ".content h4",
            lvl5: ".content h5",
          },
          indexHeadings: true,
        });
      },
    },
  ],
  initialIndexSettings: {
    vitepress: {
      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: '<span class="algolia-docsearch-suggestion--highlight">',
      highlightPostTag: "</span>",
      minWordSizefor1Typo: 3,
      minWordSizefor2Typos: 7,
      allowTyposOnNumericTokens: false,
      minProximity: 1,
      ignorePlurals: true,
      advancedSyntax: true,
      attributeCriteriaComputedByMinProximity: true,
      removeWordsIfNoResults: "allOptional",
    },
  },
});

Just sharing in case it's something specific to vitepress-recommended crawler.

Copy link

netlify bot commented Aug 15, 2024

👷 Deploy request for docsearch pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit b5e5d97

@randombeeper
Copy link
Collaborator

@brc-dd Thanks for this - we are aware of some change on our end and trying to track it down!

@brc-dd
Copy link
Contributor Author

brc-dd commented Aug 15, 2024

Thanks. Please close this PR if this is fixed at source.

@levimichael
Copy link
Contributor

@brc-dd it most likely will be fixed at the source, for now you can patch it by adding attributesToHighlight: ['hierarchy.lvl0'] to the searchParameters

@brc-dd brc-dd closed this Aug 15, 2024
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

Successfully merging this pull request may close these issues.

lvl0 Results.title category header is empty
3 participants