Skip to content

Commit

Permalink
Fixed the issue on Docs search bar issue (Results not found for some …
Browse files Browse the repository at this point in the history
…keyword)
  • Loading branch information
Santhosh-testsigma committed Nov 20, 2024
1 parent 98de7a7 commit 3433a98
Showing 1 changed file with 21 additions and 21 deletions.
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

0 comments on commit 3433a98

Please sign in to comment.