-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1839: Improve playgrounds r=Strift a=flevi29 # Pull Request ## What does this PR do? - refactor playgrounds, so that it uses the base `package.json` Vite dependency, modernize it according to https://vite.new/vanilla ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: F. Levi <[email protected]>
- Loading branch information
Showing
14 changed files
with
106 additions
and
489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,3 +132,4 @@ package | |
.idea | ||
dist_default_export_in_index | ||
no_default_export_in_index | ||
playgrounds/javascript/yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,12 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1, shrink-to-fit=no" | ||
/> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Meilisearch + Vite</title> | ||
</head> | ||
<body> | ||
<h1>Meilisearch + Vite</h1> | ||
<h2 class="errors_title">Errors:</h2> | ||
<div class="errors"></div> | ||
|
||
<h2>Movies index:</h2> | ||
<div class="indexes"></div> | ||
<h2>Search response:</h2> | ||
<div class="hits"></div> | ||
<script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4"></script> | ||
<script type="module" src="/src/app.js"></script> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
{ | ||
"name": "meilisearch-js-playground", | ||
"version": "0.2.0", | ||
"description": "Meilisearch playground written with Vite", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
}, | ||
"devDependencies": { | ||
"vite": "^6.0.9" | ||
"vite": "^6.0.11" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import "./style.css"; | ||
import { addDocuments, getAllHits, getSearchResponse } from "./meilisearch.js"; | ||
|
||
document.querySelector<HTMLDivElement>("#app")!.innerHTML = ` | ||
<div> | ||
<h1>Meilisearch + Vite</h1> | ||
<h2>Documents:</h2> | ||
<div id="hits" style="white-space: break-spaces"> - </div> | ||
<h2>Search response:</h2> | ||
<div id="response" style="white-space: break-spaces"> - </div> | ||
<h2>Errors:</h2> | ||
<div id="errors">None</div> | ||
</div> | ||
`; | ||
|
||
function getErrorMessage(error: unknown): string { | ||
if (!(error instanceof Error)) { | ||
return JSON.stringify(error); | ||
} | ||
|
||
const message = String(error); | ||
|
||
if (error.cause === undefined) { | ||
return message; | ||
} | ||
|
||
return `${message}\nCaused by ${getErrorMessage(error.cause)}`; | ||
} | ||
|
||
try { | ||
await addDocuments(); | ||
await getAllHits(document.querySelector<HTMLDivElement>("#hits")!); | ||
await getSearchResponse(document.querySelector<HTMLDivElement>("#response")!); | ||
} catch (error) { | ||
console.error(error); | ||
document.querySelector<HTMLDivElement>("#errors")!.innerText = | ||
getErrorMessage(error); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Index, Meilisearch } from "../../../src/index.js"; | ||
|
||
const client = new Meilisearch({ | ||
host: "http://127.0.0.1:7700", | ||
apiKey: "masterKey", | ||
}); | ||
const indexUid = "movies"; | ||
const index = client.index<{ id: number; title: string; genres: string[] }>( | ||
indexUid, | ||
); | ||
|
||
export async function addDocuments(): Promise<void> { | ||
await client.deleteIndexIfExists(indexUid); | ||
|
||
const task1 = await client.createIndex(indexUid); | ||
await client.waitForTask(task1.taskUid); | ||
|
||
const task2 = await index.addDocuments([ | ||
{ id: 1, title: "Carol", genres: ["Romance", "Drama"] }, | ||
{ id: 2, title: "Wonder Woman", genres: ["Action", "Adventure"] }, | ||
{ id: 3, title: "Life of Pi", genres: ["Adventure", "Drama"] }, | ||
{ | ||
id: 4, | ||
title: "Mad Max: Fury Road", | ||
genres: ["Adventure", "Science Fiction"], | ||
}, | ||
{ id: 5, title: "Moana", genres: ["Fantasy", "Action"] }, | ||
{ id: 6, title: "Philadelphia", genres: ["Drama"] }, | ||
]); | ||
|
||
await client.index(indexUid).waitForTask(task2.taskUid); | ||
} | ||
|
||
export async function getAllHits(element: HTMLDivElement): Promise<void> { | ||
const documents = await index.getDocuments(); | ||
|
||
element.innerText = JSON.stringify(documents, null, 4); | ||
} | ||
|
||
export async function getSearchResponse(element: HTMLDivElement) { | ||
const params: Parameters<Index["search"]> = [ | ||
"philoudelphia", | ||
{ attributesToHighlight: ["title"] }, | ||
]; | ||
|
||
const response = await client.index(indexUid).search(...params); | ||
|
||
element.innerText = | ||
`PARAMETERS: ${JSON.stringify(params, null, 4)}` + | ||
`\nRESPONSE: ${JSON.stringify(response, null, 4)}`; | ||
} |
6 changes: 0 additions & 6 deletions
6
playgrounds/javascript/src/index.css → playgrounds/javascript/src/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite/client" /> |
Oops, something went wrong.