Comments (4)
Thanks much for the response ... I corrected the method as you noted above it worked beautifully!
.add(doc); // pass in the object since I used the doc descriptor
Very excited about this search capability!
from flexsearch.
Hello sorry for the late answer. I do not fully understand your intend, but I can provide you a running version:
const FlexSearch = require("flexsearch");
// provide a document descriptor for each index
// the field "id" and at least one "field" is mandatory.
const settings = {
"bookstore": {
preset: "score",
doc: {
id: "id",
field: ["intent", "text"]
}
},
"pizzashop": {
encode: "extra",
tokenize: "strict",
depth: 5,
threshold: 5,
doc: {
id: "id",
field: ["intent", "text"]
}
},
"votingbooth": {
encode: "advanced",
tokenize: "forward",
threshold: 5,
doc: {
id: "id",
field: ["intent", "text"]
}
}
};
const index = {};
const add = (cat, doc) => {
(index[cat] || (
index[cat] = new FlexSearch(settings[cat])
)).add(doc);
};
const search = (cat, query) => {
return index[cat] ? index[cat].search(query) : [];
};
// provide documents which have the same structure as defined in the document descriptor above
const bookstore = [{
id: 0,
intent: "intent",
text: "text"
},{
id: 1,
intent: "intent",
text: "i am searching for a book"
}];
const pizzashop = [{
id: 0,
intent: "intent",
text: "text"
},{
id: 1,
intent: "intent",
text: "howdy"
}];
const votingbooth = [{
id: 0,
intent: "intent",
text: "text"
},{
id: 1,
intent: "intent",
text: "i need directions"
}];
// add a full document or an array of documents to the index
add("bookstore", bookstore);
add("pizzashop", pizzashop);
add("votingbooth", votingbooth);
// search
var result1 = search("bookstore", "i am searching for a book"); // --> [1]
var result2 = search("pizzashop", "howdy"); // --> [1]
var result3 = search("votingbooth", "i need directions"); // --> [1]
console.log(`========== FAST SEARCH TEST ==========`);
console.log(result1);
console.log(result2);
console.log(result3);
I hope it helps you.
from flexsearch.
You can also skip the doc descriptor and just pass one string value with index[cat].add(id, string)
, but this will return just ids as a result. If that fits your needs then this is noticeably faster.
from flexsearch.
One last thing :) the next version will provide you a "where" field in the custom search, this will replace the by-hand-category-splitting completely
from flexsearch.
Related Issues (20)
- RangeError: Invalid string length HOT 2
- How to import Document in nodejs with ESNext modules (typescript)?
- Invalid regular expression
- Suggestion and tokenize "forward"
- Webpack cannot resolve flexsearch HOT 1
- `IndexOptions` TS interface is missing some options HOT 1
- Current NPM package is stale HOT 2
- Cloning of flexsearch objects
- new Document causes `.default is not a constructor` error HOT 1
- Benchmark link is broken HOT 1
- Setting a string as "encode" doesn't work (confusing document?)
- How to return context (+ or - few lines) around the hits of given search text
- Enriched document search showing duplicate results
- I have a question about how the results are sorted
- Do not force string in Index#add() when custom encoder
- "Document Indexes" link in readme is broken
- Typo in cdn link
- TypeScript doesn't allow omitting id from the document descriptor while the README says it is allowed
- document search option "pluck" is rejected by TypeScript
- Some documents may appear multiple times in the search result
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flexsearch.