BUG FIX: typesense schema and data
This commit is contained in:
@@ -91,15 +91,20 @@ const indexAllBelongings = async () => {
|
||||
let documents = []
|
||||
|
||||
for (const belonging of belongings) {
|
||||
const categoryArray = Array.isArray(belonging.category) ? belonging.category : belonging.category ? [belonging.category] : []
|
||||
const tags = belonging.tags.join(', ')
|
||||
|
||||
const data = {
|
||||
_id: belonging._id,
|
||||
isActive: belonging.isActive,
|
||||
name: belonging.name,
|
||||
belongingCode: belonging.belongingCode,
|
||||
category: belonging.category.map((x) => x.englishName),
|
||||
nativeCategory: belonging.category.map((x) => x.nativeName),
|
||||
documents: belonging.documents,
|
||||
category: categoryArray.map((x) => x.englishName),
|
||||
nativeCategory: categoryArray.map((x) => x.nativeName),
|
||||
description: belonging.description,
|
||||
unit: belonging.unit,
|
||||
tags: tags,
|
||||
coordinates: belonging.location.coordinates,
|
||||
createdAt: Math.floor(new Date(belonging.createdAt).getTime() / 1000), // Store as timestamp in seconds
|
||||
}
|
||||
|
||||
documents.push(data)
|
||||
@@ -117,13 +122,15 @@ const getTypeSenseSchema = () => {
|
||||
enable_nested_fields: true,
|
||||
fields: [
|
||||
{ name: '_id', type: 'string', facet: false, infix: false },
|
||||
{ name: 'isActive', type: 'bool', facet: false, infix: true },
|
||||
{ name: 'belongingCode', type: 'string', facet: true },
|
||||
{ name: 'category', type: 'string[]', facet: true },
|
||||
{ name: 'nativeCategory', type: 'string[]', facet: false },
|
||||
{ name: 'documents', type: 'string[]', facet: false },
|
||||
{ name: 'name', type: 'string', facet: false, infix: true },
|
||||
{ name: 'belongingCode', type: 'int64', facet: false },
|
||||
{ name: 'category', type: 'string[]', facet: true, infix: true },
|
||||
{ name: 'nativeCategory', type: 'string[]', facet: false, infix: true },
|
||||
{ name: 'description', type: 'string', facet: false },
|
||||
{ name: 'unit', type: 'string', facet: false, infix: true },
|
||||
{ name: 'tags', type: 'string', facet: false, infix: true },
|
||||
{ name: 'coordinates', type: 'geopoint' },
|
||||
{ name: 'createdAt', type: 'int64', facet: false },
|
||||
],
|
||||
default_sorting_field: 'createdAt',
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user