Taj English
06/20/2024, 11:34 PM{
collection: 'users',
filters: {
q: '*',
filter_by: 'role:professional',
include_fields: '$businesses(*)',
},
}
Users Schema
await typesense.collections().create({
name: 'users',
fields: [
{ name: 'name', type: 'string' },
{ name: 'username', type: 'string' },
{ name: 'bio', type: 'string', optional: true },
{ name: 'tags', type: 'string[]', optional: true },
{ name: 'profilePhoto', type: 'string', index: false, optional: true },
{ name: 'address.city', type: 'string', optional: true },
{ name: 'address.state', type: 'string', optional: true },
{ name: 'address.zip', type: 'string', optional: true },
{ name: 'address.country', type: 'string', optional: true },
{ name: 'address.location.coordinates', type: 'geopoint', sort: true, optional: true },
{ name: 'businessId', type: 'string', optional: true, reference: 'businesses.id' },
{ name: 'role', type: 'string' },
{ name: 'createdAt', type: 'int64' },
{ name: 'updatedAt', type: 'int64' },
],
enable_nested_fields: true,
});
Businesses Schema
await typesense.collections().create({
name: 'businesses',
fields: [
{ name: 'name', type: 'string', optional: true },
{ name: 'tags', type: 'string[]', optional: true },
{ name: 'billing.plan', type: 'string', optional: true },
{ name: 'billing.subscribed', type: 'bool', optional: true },
{ name: 'locations', type: 'object[]', optional: true },
{ name: 'locations.mobile', type: 'bool[]' },
{ name: 'locations.address', type: 'object', optional: true },
{ name: 'locations.address.city', type: 'string[]', optional: true },
{ name: 'locations.address.state', type: 'string[]', optional: true },
{ name: 'locations.address.zip', type: 'string[]', optional: true },
{ name: 'locations.address.country', type: 'string[]', optional: true },
{ name: 'locations.address.location.coordinates', type: 'geopoint', sort: true, optional: true },
{ name: 'createdAt', type: 'int64' },
{ name: 'updatedAt', type: 'int64' },
],
enable_nested_fields: true,
});
Jason Bosco
06/21/2024, 3:22 PMTaj English
06/21/2024, 3:35 PMTaj English
06/21/2024, 3:35 PMTaj English
06/21/2024, 3:38 PMTaj English
06/21/2024, 3:40 PMTaj English
06/21/2024, 3:40 PMinclude_fields
?Jason Bosco
06/21/2024, 3:41 PMJason Bosco
06/21/2024, 3:42 PMTaj English
06/21/2024, 4:06 PMJason Bosco
06/21/2024, 4:07 PMTaj English
06/21/2024, 7:32 PMTaj English
06/21/2024, 7:41 PM