Create a Lyra database from anywhere.
You can install Lyra using npm
, yarn
, pnpm
:
npm i @mateonunez/lyra-impact
yarn add @mateonunez/lyra-impact
pnpm add @mateonunez/lyra-impact
See the full list of examples: mateonunez/lyra-impact-examples
import { search } from "@lyrasearch/lyra"
import { impact } from "@mateonunez/lyra-impact"
(async () => {
const lyra = await impact("https://raw.githubusercontent.com/LyraSearch/lyra/main/examples/with-vue/public/pokedex.json")
const { hits } = await search(lyra, { term: "pikachu" })
console.log(hits)
})();
Result
[
{
num: '025',
name: 'Pikachu',
img: 'http://www.serebii.net/pokemongo/pokemon/025.png',
type: [ 'Electric' ],
height: '0.41 m',
weight: '6.0 kg',
candy: 'Pikachu Candy',
candy_count: 50,
egg: '2 km',
spawn_chance: 0.21,
avg_spawns: 21,
spawn_time: '04:00',
multipliers: [ 2.34 ],
weaknesses: [ 'Ground' ],
next_evolution: [ { num: '026', name: 'Raichu' } ]
}
];
lyra-impact
supports the following formats and fetchers:
Format | Fetcher | Description |
---|---|---|
JSON |
fetch , filesystem |
Fetches a JSON response or file |
GraphQL |
graphql |
Fetches a GraphQL endpoint |
CSV |
fetch , filesystem |
Fetches a CSV file from a URL or filesystem |
XML (REMOVED) |
fetch , filesystem |
Fetches a XML file from a URL or filesystem |
import { search } from "@lyrasearch/lyra"
import { impact } from "@mateonunez/lyra-impact"
(async () => {
const lyra = await impact("https://rickandmortyapi.com/graphql", {
fetch: {
fetcher: "graphql",
query: `{
characters {
results {
type
status
species
name
id
gender
}
}
}`,
property: "characters.results"
}
})
const { hits } = await search(lyra, {
term: "Morty"
})
console.log(hits)
})()
import { search } from "@lyrasearch/lyra"
import { impact } from "@mateonunez/lyra-impact"
(async () => {
const lyra = await impact("./data/examples/characters.csv", {
fetch: {
fetcher: "filesystem"
}
})
const { hits } = await search(lyra, {
term: "Morty"
})
console.log(hits)
})()
collision
method allows you to fetch and search a term in the API results.
url: string
searchOptions: SearchOptions
impactOptions: ImpactOptions
import { collision } from "@mateonunez/lyra-impact"
(async () => {
const { hits } = await collision("https://raw.githubusercontent.com/LyraSearch/lyra/main/examples/with-vue/public/pokedex.json", {
term: "pikachu"
})
console.log(hits)
})();
Result
[
{
num: '025',
name: 'Pikachu',
img: 'http://www.serebii.net/pokemongo/pokemon/025.png',
type: [ 'Electric' ],
height: '0.41 m',
weight: '6.0 kg',
candy: 'Pikachu Candy',
candy_count: 50,
egg: '2 km',
spawn_chance: 0.21,
avg_spawns: 21,
spawn_time: '04:00',
multipliers: [ 2.34 ],
weaknesses: [ 'Ground' ],
next_evolution: [ { num: '026', name: 'Raichu' } ]
}
];