Skip to content

Commit

Permalink
Merge #1185
Browse files Browse the repository at this point in the history
1185: Fix javascript playground r=bidoubiwa a=bidoubiwa

After trying out the playground usinfg `yarn playground:javascript` it would not run. This PR fixes the issue

Co-authored-by: Charlotte Vermandel <charlottevermandel@gmail.com>
  • Loading branch information
meili-bors[bot] and bidoubiwa committed Apr 7, 2022
2 parents 7edaffa + 8cbb977 commit 7a3220f
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions playgrounds/javascript/src/app.js
@@ -1,4 +1,4 @@
import { MeiliSearch } from '../../../src/lib/meilisearch'
import { MeiliSearch } from '../../../src'

const config = {
host: 'http://127.0.0.1:7700',
Expand All @@ -9,11 +9,11 @@ const client = new MeiliSearch(config)
const indexUid = 'movies'

const addDataset = async () => {
const index = await client.deleteIndex(indexUid)
await client.deleteIndex(indexUid)
const { uid } = await client.createIndex(indexUid)
await index.waitForTask(uid)
await client.index(indexUid).waitForTask(uid)

const documents = await index.getDocuments()
const documents = await client.index(indexUid).getDocuments()

const dataset = [
{ id: 1, title: 'Carol', genres: ['Romance', 'Drama'] },
Expand All @@ -28,8 +28,8 @@ const addDataset = async () => {
{ id: 6, title: 'Philadelphia', genres: ['Drama'] },
]
if (documents.length === 0) {
const task = await index.addDocuments(dataset)
await index.waitForPendingUpdate(task.uid)
const task = await client.index(indexUid).addDocuments(dataset)
await client.index(indexUid).waitForTask(task.uid)
}
}

Expand All @@ -40,25 +40,21 @@ const addDataset = async () => {
document.querySelector('.indexes').innerText = JSON.stringify(
indexes,
null,
2
)
const resp = await client.index(indexUid).search(
'',
{
attributesToHighlight: ['title'],
},
'POST'
1
)
const resp = await client.index(indexUid).search('', {
attributesToHighlight: ['title'],
})
console.log({ resp })
console.log({ hit: resp.hits[0] })
document.querySelector('.hits').innerText = JSON.stringify(
resp.hits,
resp.hits.map((hit) => hit.title),
null,
2
1
)
document.querySelector('.errors_title').style.display = 'none'
} catch (e) {
console.error(e)
document.querySelector('.errors').innerText = JSON.stringify(e, null, 2)
document.querySelector('.errors').innerText = JSON.stringify(e, null, 1)
}
})()

0 comments on commit 7a3220f

Please sign in to comment.