Resolving 'typesense is not defined' Error
TLDR Tim couldn't run Typesense due to a missing import statement. Masahiro and Jason helped identify the issue and adjusted the documentation accordingly.
1
Apr 05, 2021 (34 months ago)
Tim
06:54 AMMasahiro
06:57 AMTim
07:00 AMvar readline = require('readline');
let client = new Typesense.Client({
'nodes': [{
'host': 'localhost',
'port': '8108',
'protocol': 'http'
}],
'apiKey': '<API_KEY>',
'connectionTimeoutSeconds': 2
})
let booksSchema = {
'name': 'books',
'fields': [
{'name': 'title', 'type': 'string' },
{'name': 'authors', 'type': 'string[]' },
{'name': 'image_url', 'type': 'string' },
{'name': 'publication_year', 'type': 'int32' },
{'name': 'ratings_count', 'type': 'int32' },
{'name': 'average_rating', 'type': 'float' },
{'name': 'authors_facet', 'type': 'string[]', 'facet': true },
{'name': 'publication_year_facet', 'type': 'string', 'facet': true },
],
'default_sorting_field': 'ratings_count'
}
client.collections().create(booksSchema)
.then(function (data) {
console.log(data)
})
readline.createInterface({
input: fs.createReadStream('./books.jsonl'),
terminal: false
}).on('line', function(line) {
let bookDocument = JSON.parse(line);
client.collections('books').documents().create(bookDocument)
});
let searchParameters = {
'q' : 'harry',
'query_by' : 'title',
'sort_by' : 'ratings_count:desc'
}
client.collections('books')
.documents()
.search(searchParameters)
.then(function (searchResults) {
console.log(searchResults)
})
Tim
07:00 AMMasahiro
07:04 AMnpm i
in your working director?Tim
07:06 AMTim
07:06 AMMasahiro
07:52 AMimport Typesense from 'typesense'
Jason
10:28 PMJason
10:29 PMJason
10:48 PM1
Typesense
Indexed 3015 threads (79% resolved)
Similar Threads
Typescript Support and Import Issues with Typesense
Ahmad faced trouble with Typesense support for Typescript. Jason assisted by suggesting checks and solutions. Phil suggested modifying the import statement. Ultimately, the issue was resolved with a change from Jason in version `v1.1.2`.
Troubleshooting Typescript Error with Typesense
Amrit encounters a Typescript error and Jason suggests checking Typesense FieldType and importing it from 'typesense/lib/Typesense/Collections'.
Typesense-JS Client Types Importation Problem.
Stefan had problems importing types from typesense-JS, causing compiler slowdowns. Jason and Damian provided guidance and agreed to export necessary types from Typesense.ts, improving import speed and reducing compiler checks.
Using TypeScript with Typesense JS Library
michtio asked how to use TypeScript with Typesense JS library, and Ross provided detailed example code.
Issues with TypesenseClient Import in Typescript
David struggled to find correct import syntax for TypesenseClient in TypeScript, and Jason clarified the proper usage. The documentation for the import will now be updated.