Micro-document full-text index.
Allows search over a large number of small strings (i.e. micro-documents). Alternatively, allows macro-documents (e.g. a book or a chapter) to be split into micro-documents (e.g. pages or lines) and get more specifically scoped search results.
The search space has three tiers:
- Micro-documents (i.e. small strings).
- Macro-documents, to which the searchable strings belong.
- Domains, or top-level search segments. Essentially namespaces.
A query takes place within a domain and returns micro-documents grouped into macro-documents.
So taking the book example above, the domain might be "Shakespeare", and our results might be names of plays and lines within those plays that match supplied keywords.
var microdex = require("microdex");
microdex.init();
microdex.schema.create(err => {
microdex.index("Shakespeare", "Romeo and Juliet", [ /* lines */ ], err => {
microdex.search("Shakespeare", "wherefore are thou romeo", (err, results) => {
console.log(results) // { query: "wherefore...", time: 200, results: [ ] }
});
});
});
- Uses AWS DynamoDB as storage and query medium.
- Removes stop words to increase precision.
- Employs English language stemming and phonetics for improved recall.
- Support for query expansion.
- Small string compression to increase capacity.
Per DynamoDB limitations:
- Each macro-document can contain 400kB of micro-documents.
- Each search term within a macro-document can point to 400kB of micro-documents.
npm install microdex
var microdex = require("microdex");
// Initialize with AWS DynamoDB options + a parallelism option
microdex.init({ });
// Initialize with create options found in Dynq
microdex.schema.create({ }, err => { });
The core API is purposely designed to be very simple.
Indexes one or more micro-documents within a given domain and macro-document.
Deletes one or more micro-documents within a given domain and macro-document.
Searches a domain with a given query.
Internally, microdex
uses a lang
module which is customizable.
The terms method is used to extract search terms from a query or micro-document. Use for your own purposes, or even override it if you dare.
An array of stopwords that the terms
methods removes from text.
Query expansion adds search terms when it finds base terms. For example, you might want to search on "university" when you see the word "college".
Removes expansions that added with the method above.
Adds metadata to a micro-document that should not be indexed. This is accomplished by separating the two by a special divider string (see below). For example, if each micro-document is a line within a macro-document, you may wish to store a line number along with the literal text.
A string that is used as a separator between micro-document text and metadata.