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

Fixed the issue on Docs search bar issue (Results not found for some keyword) #534

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions scripts/indexr.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require("dotenv").config({
require('dotenv').config({
path: `.env`,
});
const Typesense = require("typesense");
const { request } = require("graphql-request");
const Typesense = require('typesense');
const { request } = require('graphql-request');

const pageQuery = `
query {
Expand All @@ -13,7 +13,7 @@ const pageQuery = `
) {
edges {
node {
headings(depth: h3) {
headings(depth: h4) {
value
}
objectID: id
Expand All @@ -29,7 +29,7 @@ const pageQuery = `
fields {
slug
}
excerpt(pruneLength: 100)
excerpt(pruneLength: 200000)
}
}
}
Expand All @@ -39,13 +39,13 @@ const pageQuery = `
function pageToTypesenseRecord({ node }) {
const { id, frontmatter, fields = {}, headings = [], ...rest } = node;

const formattedHeadings = headings.map((h) => h.value || "").filter(Boolean);
const formattedHeadings = headings.map((h) => h.value || '').filter(Boolean);
return {
objectID: id,
title: frontmatter.title || "",
search_keyword: String(frontmatter.search_keyword || ""),
slug: fields.slug || "",
excerpt: frontmatter.excerpt || "",
title: frontmatter.title || '',
search_keyword: String(frontmatter.search_keyword || ''),
slug: fields.slug || '',
excerpt: frontmatter.excerpt || '',
headings: formattedHeadings,
...rest,
};
Expand Down Expand Up @@ -84,23 +84,23 @@ async function indexData() {
await client.collections().create({
name: process.env.TYPESENSE_COLLECTION,
fields: [
{ name: "objectID", type: "string" },
{ name: "title", type: "string" },
{ name: "search_keyword", type: "string" },
{ name: "slug", type: "string" },
{ name: "excerpt", type: "string" },
{ name: "headings", type: "string[]", facet: false },
{ name: 'objectID', type: 'string' },
{ name: 'title', type: 'string' },
{ name: 'search_keyword', type: 'string' },
{ name: 'slug', type: 'string' },
{ name: 'excerpt', type: 'string' },
{ name: 'headings', type: 'string[]', facet: false },
],
});
console.log(
`Collection ${process.env.TYPESENSE_COLLECTION} created successfully.`
);

const response = await request(
"http://127.0.0.1:8000/___graphql",
'http://127.0.0.1:8000/___graphql',
pageQuery
);
console.log("response", response);
console.log('response', response);
const data = await response;

const records = data.docs.edges.map(pageToTypesenseRecord);
Expand All @@ -111,16 +111,16 @@ async function indexData() {
.import(records)
.then((typesenseResponse) => {
// check the output of the response in the console
console.log("typesenseResponse", typesenseResponse);
console.log('typesenseResponse', typesenseResponse);
console.log(`🎉 Successfully indexed records to Typesense search.`);
})
.catch((error) => {
console.error(error);
});

console.log("Indexing complete!");
console.log('Indexing complete!');
} catch (error) {
console.error("Indexing error:", error);
console.error('Indexing error:', error);
}
}

Expand Down
Loading