-
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds search hits, elapsed time, and count
- Loading branch information
1 parent
6fac8f2
commit b2a23c0
Showing
12 changed files
with
28,449 additions
and
26 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 |
---|---|---|
|
@@ -4,4 +4,6 @@ jest.config.js | |
.eslintrc.cjs | ||
*.yaml | ||
*.md | ||
*.snap | ||
*.snap | ||
*.csv | ||
*.sh |
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 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,22 @@ | ||
import yargs from "yargs"; | ||
|
||
export function commands(input: string) { | ||
return yargs(input as unknown as string[]) | ||
.command("search <text...>", "searches a text") | ||
.option("limit", { | ||
alias: "l", | ||
type: "number", | ||
default: 10, | ||
}) | ||
.option("offset", { | ||
alias: "o", | ||
type: "number", | ||
default: 0, | ||
}) | ||
.option("properties", { | ||
alias: "p", | ||
type: "string", | ||
default: "*", | ||
}) | ||
.parse(); | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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,4 @@ | ||
wget https://datasets.imdbws.com/title.episode.tsv.gz -O ./datasets/title.basics.tsv.gz | ||
gzip -d ./datasets/title.basics.tsv.gz | ||
head -n1000000 ./datasets/title.basics.tsv >> ./datasets/title.basics.short.tsv | ||
rm ./datasets/title.basics.tsv |
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,24 @@ | ||
{ | ||
"name": "@nearform/lyra-repl", | ||
"description": "Repl for the Lyra search engine", | ||
"version": "0.0.1", | ||
"author": { | ||
"name": "Michele Riva", | ||
"email": "ciao@micheleriva.it", | ||
"url": "https://github.com/MicheleRiva" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/nearform/lyra" | ||
}, | ||
"dependencies": { | ||
"@nearform/lyra": "workspace:^", | ||
"csv": "^6.0.5", | ||
"yargs": "^17.5.1" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^27.5.0", | ||
"@types/yargs": "^17.0.10", | ||
"jest": "^28.1.0", | ||
"ts-jest": "^28.0.2" | ||
} | ||
} |
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,68 @@ | ||
import readline from "readline"; | ||
import { Lyra } from "@nearform/lyra"; | ||
import dataset from "./datasets/reviews.json"; | ||
import { commands } from "./commands"; | ||
|
||
type Dataset = { | ||
"": string; | ||
Rating: string; | ||
"Review Text": string; | ||
"Division Name": string; | ||
Title: string; | ||
"Recommended IND": string; | ||
Age: string; | ||
"Department Name": string; | ||
"Class Name": string; | ||
"Positive Feedback Count": string; | ||
"Clothing ID": string; | ||
}; | ||
|
||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
terminal: false, | ||
}); | ||
|
||
const db = new Lyra({ | ||
schema: { | ||
rating: "string", | ||
review: "string", | ||
title: "string", | ||
}, | ||
}); | ||
|
||
async function load() { | ||
for (const data of dataset as Dataset[]) { | ||
await db.insert({ | ||
rating: data.Rating, | ||
review: data["Review Text"], | ||
title: data.Title, | ||
}); | ||
} | ||
} | ||
|
||
async function parseLine(input: string) { | ||
const cmd = await commands(input); | ||
const tokens = (cmd as any).text.join(", "); | ||
|
||
const properties = cmd.properties === "*" ? "*" : cmd.properties.split(","); | ||
|
||
const result = await db.search({ | ||
term: tokens, | ||
limit: cmd.limit, | ||
offset: cmd.offset, | ||
properties, | ||
}); | ||
|
||
console.log(result); | ||
} | ||
|
||
async function start() { | ||
console.log("loading dataset..."); | ||
await load(); | ||
console.log(`${(dataset as any[]).length} reviews loaded`); | ||
|
||
rl.on("line", parseLine); | ||
} | ||
|
||
start(); |
Oops, something went wrong.