Skip to content

Commit

Permalink
Se soluciona error en la búsqueda por prefijos
Browse files Browse the repository at this point in the history
  • Loading branch information
jonattanva committed Dec 20, 2021
1 parent a987dd3 commit 8ece7ff
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testPathIgnorePatterns: ["!*.d.ts"],
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monolieta-search",
"version": "1.1.0",
"version": "1.1.1",
"description": "Search library for browser and Node.js",
"main": "dist/index.js",
"module": "dist/index.esm.js",
Expand Down
21 changes: 20 additions & 1 deletion src/__tests__/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe("Search", () => {
expect(search.search("hobbit")).toEqual(["002"]);
});

it("demo", () => {
it("demo 1", () => {
const client = new Search({
exactWordStrategy: false,
unorderedDocument: false,
Expand All @@ -144,4 +144,23 @@ describe("Search", () => {

expect(client.search("Ring")).toEqual(["001"]);
});

it("demo 2", () => {
const client = new Search({
caseSensitive: false,
exactWordStrategy: false,
ignoreAccent: true,
stopWord: {
de: true,
},
unorderedDocument: false,
});

client.index("003", "Piezas");
client.index("007", "Préstamo de Herramientas");
client.index("008", "Evaluación de proveedores");

expect(client.search("proveedores")).toEqual(["008"]);
expect(client.search("pr")).toEqual(["007", "008"]);
});
});
6 changes: 2 additions & 4 deletions src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ export class Search {
this.document.insert(uid, this.strategy.apply(this.prepare(body)));
}

search(text: string): string[] {
return this.document.search(
this.strategy.apply(this.tokenizer.tokenize(text))
);
search(query: string): string[] {
return this.document.search(this.tokenizer.tokenize(query));
}

isEmpty() {
Expand Down

0 comments on commit 8ece7ff

Please sign in to comment.