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