1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-09-09 21:50:49 +02:00

readme update document options

This commit is contained in:
Thomas Wilkerling
2025-05-07 11:11:32 +02:00
parent 3bd342e74c
commit 5ebe58065c
10 changed files with 202 additions and 388 deletions

View File

@@ -237,32 +237,38 @@ Extern Projects & Plugins:
- [Module (ESM)](#module-esm) - [Module (ESM)](#module-esm)
- [Node.js](#nodejs) - [Node.js](#nodejs)
- [Basic Usage and Variants](#basic-usage-and-variants) - [Basic Usage and Variants](#basic-usage-and-variants)
- [Index Options](#index-options)
- [Search Options](#search-options)
- [Common Code Examples (Browser, Node.js)](#common-code-examples) - [Common Code Examples (Browser, Node.js)](#common-code-examples)
- [API Overview](#api-overview) - [API Overview](#api-overview)
- [Options](doc/options.md)
- [Index Options](#index-options)
- [Document Options](doc/options.md)
- [Worker Index Options](doc/worker.md#worker-index-options)
- [Persistent Options](doc/options.md)
- [Encoder Options](doc/encoder.md#encoder-options)
- [Resolver Options](doc/options.md)
- [Presets](#presets) - [Presets](#presets)
- [Context Search](#context-search) - [Context Search](#context-search)
- [Context Options](#context-options)
- [Fast-Update Mode](#fast-update-mode) - [Fast-Update Mode](#fast-update-mode)
- [Suggestions](#suggestions) - [Suggestions](#suggestions)
- [Document Search (Multi-Field Search)](doc/document-search.md) - [Document Search (Multi-Field Search)](doc/document-search.md)
- [Multi-Tag Search](doc/document-search.md) - [Document Index Options](doc/document-search.md#document-options)
- [Document Descriptor](doc/document-search.md#the-document-descriptor)
- [Document Search Options](doc/document-search.md#document-search-options)
- [Multi-Tag Search](doc/document-search.md)
- [Result Highlighting](doc/result-highlighting.md)
- [Highlighting Options](doc/result-highlighting.md#highlighting-options)
- [Boundary Options](doc/result-highlighting.md#highlighting-boundary-options)
- [Ellipsis Options](doc/result-highlighting.md#highlighting-ellipsis-options)
- [Phonetic Search (Fuzzy Search)](#fuzzy-search) - [Phonetic Search (Fuzzy Search)](#fuzzy-search)
- [Tokenizer (Partial Search)](#tokenizer-partial-match) - [Tokenizer (Partial Search)](#tokenizer-partial-match)
- [Charset Collection](#charset-collection) - [Charset Collection](#charset-collection)
- [Encoder](doc/encoder.md) - [Encoder](doc/encoder.md)
- [Encoder Options](doc/encoder.md#encoder-options)
- [Universal Charset Collection](doc/encoder.md) - [Universal Charset Collection](doc/encoder.md)
- [Latin Charset Encoder Presets](doc/encoder.md) - [Latin Charset Encoder Presets](doc/encoder.md)
- [Language Specific Preset](doc/encoder.md) - [Language Specific Preset](doc/encoder.md)
- [Custom Encoder](doc/encoder.md#custom-encoder) - [Custom Encoder](doc/encoder.md#custom-encoder)
- [Non-Blocking Runtime Balancer (Async)](doc/async.md) - [Non-Blocking Runtime Balancer (Async)](doc/async.md)
- [Worker Indexes](doc/worker.md) - [Worker Indexes](doc/worker.md)
- [Worker Index Options](doc/worker.md#worker-index-options)
- [Resolver (Complex Queries)](doc/resolver.md) - [Resolver (Complex Queries)](doc/resolver.md)
- [Resolver Options](doc/resolver.md)
- [Boolean Operations (and, or, xor, not)](doc/resolver.md) - [Boolean Operations (and, or, xor, not)](doc/resolver.md)
- [Boost](doc/resolver.md) - [Boost](doc/resolver.md)
- [Limit / Offset](doc/resolver.md) - [Limit / Offset](doc/resolver.md)
@@ -271,13 +277,13 @@ Extern Projects & Plugins:
- [Export / Import Indexes](doc/export-import.md) - [Export / Import Indexes](doc/export-import.md)
- [Fast-Boot Serialization](doc/export-import.md#fast-boot-serialization-for-server-side-rendering-php-python-ruby-rust-java-go-nodejs-) - [Fast-Boot Serialization](doc/export-import.md#fast-boot-serialization-for-server-side-rendering-php-python-ruby-rust-java-go-nodejs-)
- [Persistent Indexes](doc/persistent.md) - [Persistent Indexes](doc/persistent.md)
- [Persistent Index Options](doc/persistent.md)
- [IndexedDB (Browser)](doc/persistent-indexeddb.md) - [IndexedDB (Browser)](doc/persistent-indexeddb.md)
- [Postgres](doc/persistent-postgres.md) - [Postgres](doc/persistent-postgres.md)
- [Redis](doc/persistent-redis.md) - [Redis](doc/persistent-redis.md)
- [MongoDB](doc/persistent-mongodb.md) - [MongoDB](doc/persistent-mongodb.md)
- [SQLite](doc/persistent-sqlite.md) - [SQLite](doc/persistent-sqlite.md)
- [Clickhouse](doc/persistent-clickhouse.md) - [Clickhouse](doc/persistent-clickhouse.md)
- [Result Highlighting](doc/result-highlighting.md)
- [Custom Score Function](doc/customization.md) - [Custom Score Function](doc/customization.md)
- [Custom Builds](doc/custom-builds.md) - [Custom Builds](doc/custom-builds.md)
- [Extended Keystores (In-Memory)](doc/keystore.md) - [Extended Keystores (In-Memory)](doc/keystore.md)
@@ -1014,18 +1020,6 @@ Methods `.export()` and also `.import()` are always async as well as every metho
- [**de**](doc/encoder.md#built-in-language-packs) - [**de**](doc/encoder.md#built-in-language-packs)
- [**fr**](doc/encoder.md#built-in-language-packs) - [**fr**](doc/encoder.md#built-in-language-packs)
## Options
- [Index Options](doc/options.md)
- [Context Options](doc/options.md)
- [Document Options](doc/options.md)
- [Encoder Options](doc/encoder.md#property-overview)
- [Resolver Options](doc/options.md)
- [Search Options](doc/options.md)
- [Document Search Options](doc/options.md)
- [Worker Options](doc/options.md)
- [Persistent Options](doc/options.md)
## Basic Usage ## Basic Usage
#### Create a new index #### Create a new index
@@ -1044,9 +1038,7 @@ Create a new index with custom options:
```js ```js
const index = new Index({ const index = new Index({
tokenize: "forward", tokenize: "forward"
resolution: 9,
fastupdate: true
}); });
``` ```
@@ -1063,7 +1055,6 @@ var index = new FlexSearch({
Create a new index and assign an [Encoder](doc/encoder.md): Create a new index and assign an [Encoder](doc/encoder.md):
```js ```js
//import { Charset } from "./dist/module/charset.js";
import { Charset } from "flexsearch"; import { Charset } from "flexsearch";
const index = new Index({ const index = new Index({
tokenize: "forward", tokenize: "forward",
@@ -1071,8 +1062,10 @@ const index = new Index({
}); });
``` ```
» [Resolution](#resolution)<br> Related Topics: [Index Options](#index-options)
» [All available custom options](doc/options.md) &ensp;&bull;&ensp; [Resolution](#resolution)
&ensp;&bull;&ensp; [Charset Collection](#charset-collection)
&ensp;&bull;&ensp; [Tokenizer](#tokenizer-partial-match)
#### Add text item to an index #### Add text item to an index
@@ -1298,6 +1291,38 @@ index.remove(0).update(1, 'foo').add(2, 'foobar');
</tr> </tr>
</table> </table>
## Search Options
<table>
<tr><td colspan="4"></td></tr>
<tr>
<td>Option</td>
<td>Values</td>
<td>Description</td>
<td>Default</td>
</tr>
<tr>
<td>limit</td>
<td>number</td>
<td>Sets the limit of results.</td>
<td>100</td>
</tr>
<tr></tr>
<tr>
<td>offset</td>
<td>number</td>
<td>Apply offset (skip items).</td>
<td>0</td>
</tr>
<tr></tr>
<tr>
<td>suggest</td>
<td>Boolean</td>
<td>Enables <a href="#suggestions">suggestions</a> in results.</td>
<td>false</td>
</tr>
</table>
## Suggestions ## Suggestions
Any query on each of the index types is supporting the option `suggest: true`. Also within some of the `Resolver` stages (and, not, xor) you can add this option for the same purpose. Any query on each of the index types is supporting the option `suggest: true`. Also within some of the `Resolver` stages (and, not, xor) you can add this option for the same purpose.
@@ -1630,7 +1655,7 @@ const result = index.search("1 2 3");
// --> [2, 1] // --> [2, 1]
``` ```
The first index returns ID 1 in the first slot for the best pick, because matched terms are closer to the document root. The 2nd index has context enabled and returns the ID 2 in the first slot, because of the distance between terms. The first index returns ID 1 in the first slot for the best pick, because matched terms are closer to the document root. The 2nd index has context enabled and returns the ID 2 in the first slot, because of the shorter distance between terms.
### Context Options ### Context Options

View File

@@ -14,10 +14,156 @@ FlexSearch Documents also contain these features:
- Worker - Worker
- Persistent - Persistent
### Document Options
> Document options basically inherits from [Index Options](../README.md#index-options), so you can apply most of those options either in the top scope of the config (for all fields) or as per field or both of them.
<table>
<tr></tr>
<tr>
<td>Option</td>
<td>Values</td>
<td>Description</td>
<td>Default</td>
</tr>
<tr>
<td>document</td>
<td><a href="#the-document-descriptor">Document Descriptor</a></td>
<td>Includes any specific information about how the document data should be indexed</td>
<td style="font-style: italic">(mandatory)</td>
</tr>
<tr></tr>
<tr>
<td>worker</td>
<td>Boolean<br>String</td>
<td>Enable a worker distributed model. Read more about here: <a href="worker.md">Worker Index</a></td>
<td><code>false</code></td>
</tr>
</table>
### Document Search Options
> Document search options basically inherits from [Index Search Options](../README.md#search-options), so you can apply most of those options either in the top scope of the config (for all fields) or as per field or both of them.
<table>
<tr></tr>
<tr>
<td>Option</td>
<td>Values</td>
<td>Description</td>
<td>Default</td>
</tr>
<tr>
<td>index</td>
<td>String<br>Array&lt;String&gt;<br>Array&lt;SearchOptions&gt;</td>
<td>Sets the <a href="#docs">document fields</a> which should be searched. When no field is set, all fields will be searched. <a href="#options-field-search">Custom options per field</a> are also supported.</td>
<td></td>
</tr>
<tr></tr>
<tr>
<td>tag</td>
<td>Object&lt;field:tag&gt;</td>
<td>Sets the <a href="#docs">document fields</a> which should be searched. When no field is set, all fields will be searched. <a href="#options-field-search">Custom options per field</a> are also supported.</td>
<td></td>
</tr>
<tr></tr>
<tr>
<td>enrich</td>
<td>Boolean</td>
<td>Enrich IDs from the results with the corresponding documents.</td>
<td><code>false</code></td>
</tr>
<tr></tr>
<tr>
<td>merge</td>
<td>Boolean</td>
<td>Merge multiple fields in resultset into one and group results per ID</td>
<td><code>false</code></td>
</tr>
<tr></tr>
<tr>
<td>pluck</td>
<td>String</td>
<td>Pick and apply search to just one field and return a flat result representation</td>
<td><code>false</code></td>
</tr>
</table>
## The Document Descriptor ## The Document Descriptor
When creating a `Document`-Index you will need to define a document descriptor in the field `document`. This descriptor is including any specific information about how the document data should be indexed. When creating a `Document`-Index you will need to define a document descriptor in the field `document`. This descriptor is including any specific information about how the document data should be indexed.
<table>
<tr></tr>
<tr>
<td>Option</td>
<td>Values</td>
<td>Description</td>
<td>Default</td>
</tr>
<tr>
<td>id</td>
<td>String</td>
<td vertical-align="top"></td>
<td><code>"id"</code></td>
</tr>
<tr></tr>
<tr>
<td>index</td>
<td>String<br>Array&lt;String><br>Array&lt;FieldOptions></td>
<td></td>
<td></td>
</tr>
<tr></tr>
<tr>
<td>tag</td>
<td>String<br>Array&lt;String><br>Array&lt;FieldOptions></td>
<td></td>
<td></td>
</tr>
<tr></tr>
<tr>
<td>store</td>
<td>Boolean<br>String<br>Array&lt;String><br>Array&lt;FieldOptions></td>
<td></td>
<td><code>false</code></td>
</tr>
</table>
### Field Options
> You can use all standard [Index Options](../README.md#index-options) within field options.
<table>
<tr></tr>
<tr>
<td>Option</td>
<td>Values</td>
<td>Description</td>
<td>Default</td>
</tr>
<tr>
<td>field</td>
<td>String</td>
<td>The field name (colon seperated syntax)</td>
<td style="font-style: italic">(mandatory)</td>
</tr>
<tr></tr>
<tr>
<td>filter</td>
<td>Function</td>
<td></td>
<td></td>
</tr>
<tr></tr>
<tr>
<td>custom</td>
<td>Function</td>
<td></td>
<td></td>
</tr>
</table>
Assuming our document has a simple data structure like this: Assuming our document has a simple data structure like this:
```json ```json
@@ -73,7 +219,7 @@ const index = new Document({
}); });
``` ```
Add both fields to the document descriptor and pass individual [Index-Options](options.md) for each field: Add both fields to the document descriptor and pass individual [Index-Options](../README.md#index-options) for each field:
```js ```js
const index = new Document({ const index = new Document({
@@ -447,7 +593,7 @@ index.search(query, { limit: 20, offset: 100 });
> You cannot pre-count the size of the result-set. That's a limit by the design of FlexSearch. When you really need a count of all results you are able to page through, then just assign a high enough limit and get back all results and apply your paging offset manually (this works also on server-side). FlexSearch is fast enough that this isn't an issue. > You cannot pre-count the size of the result-set. That's a limit by the design of FlexSearch. When you really need a count of all results you are able to page through, then just assign a high enough limit and get back all results and apply your paging offset manually (this works also on server-side). FlexSearch is fast enough that this isn't an issue.
[See all available field-search options](options.md) [See all available field-search options](../README.md#search-options)
## The Result Set ## The Result Set

View File

@@ -1,110 +0,0 @@
## Document Options
<table>
<tr><td colspan="4"></td></tr>
<tr>
<td>Option</td>
<td>Values</td>
<td>Description</td>
<td>Default</td>
</tr>
<tr>
<td>id<br></td>
<td>String</td>
<td vertical-align="top"></td>
<td>"id""</td>
</tr>
<tr></tr>
<tr>
<td>tag<br><br></td>
<td>false<br>String</td>
<td vertical-align="top"></td>
<td>"tag"</td>
</tr>
<tr></tr>
<tr>
<td>index<br><br><br></td>
<td>String<br>Array&lt;String><br>Array&lt;Object></td>
<td vertical-align="top"></td>
<td></td>
</tr>
<tr></tr>
<tr>
<td>store<br><br><br></td>
<td>Boolean<br>String<br>Array&lt;String></td>
<td vertical-align="top"></td>
<td>false</td>
</tr>
</table>
## Search Options
<table>
<tr><td colspan="4"></td></tr>
<tr>
<td>Option</td>
<td>Values</td>
<td>Description</td>
<td>Default</td>
</tr>
<tr>
<td>limit</td>
<td>number</td>
<td>Sets the limit of results.</td>
<td>100</td>
</tr>
<tr></tr>
<tr>
<td>offset</td>
<td>number</td>
<td>Apply offset (skip items).</td>
<td>0</td>
</tr>
<tr></tr>
<tr>
<td>suggest</td>
<td>Boolean</td>
<td>Enables <a href="#suggestions">suggestions</a> in results.</td>
<td>false</td>
</tr>
</table>
## Document Search Options
<table>
<tr><td colspan="4"></td></tr>
<tr>
<td>Option</td>
<td>Values</td>
<td>Description</td>
<td>Default</td>
</tr>
<tr>
<td>index</td>
<td>String<br>Array&lt;String&gt;<br>Array&lt;Object&gt;</td>
<td>Sets the <a href="#docs">document fields</a> which should be searched. When no field is set, all fields will be searched. <a href="#options-field-search">Custom options per field</a> are also supported.</td>
<td></td>
</tr>
<tr></tr>
<tr>
<td>tag</td>
<td>String<br>Array&lt;String></td>
<td>Sets the <a href="#docs">document fields</a> which should be searched. When no field is set, all fields will be searched. <a href="#options-field-search">Custom options per field</a> are also supported.</td>
<td>false</td>
</tr>
<tr></tr>
<tr>
<td>enrich</td>
<td>Boolean</td>
<td>Enrich IDs from the results with the corresponding documents.</td>
<td>false</td>
</tr>
<tr></tr>
<tr>
<td>bool</td>
<td>"and"<br>"or"</td>
<td>Sets the used <a href="#operators">logical operator</a> when searching through multiple fields or tags.</td>
<td>"or"</td>
</tr>
</table>

3
index.d.ts vendored
View File

@@ -388,7 +388,7 @@ declare module "flexsearch" {
D extends DocumentData = DocumentData, D extends DocumentData = DocumentData,
W extends WorkerType = false, W extends WorkerType = false,
B extends StorageInterface = undefined B extends StorageInterface = undefined
> = IndexOptions<B> & { > = IndexOptions<B> & DocumentDescriptor<D> & {
worker?: W; worker?: W;
doc?: DocumentDescriptor<D>; doc?: DocumentDescriptor<D>;
document?: DocumentDescriptor<D>; document?: DocumentDescriptor<D>;
@@ -430,7 +430,6 @@ declare module "flexsearch" {
? EnrichedDocumentSearchResults<D> ? EnrichedDocumentSearchResults<D>
: DefaultDocumentSearchResults : DefaultDocumentSearchResults
/** /**
* # Document Search Result * # Document Search Result
* *

View File

@@ -1,41 +0,0 @@
declare module "flexsearch/db/clickhouse" {
type IdType =
"text" |
"char" |
"varchar" |
"string" |
"number" |
"numeric" |
"integer" |
"smallint" |
"tinyint" |
"mediumint" |
"int" |
"int8" |
"uint8" |
"int16" |
"uint16" |
"int32" |
"uint32" |
"int64" |
"uint64" |
"bigint";
type PersistentOptions = {
name?: string;
type?: IdType;
db?: any;
};
export default class StorageInterface {
constructor(name: string, config: PersistentOptions);
constructor(config: string | PersistentOptions);
//mount(index: Index | Document) : Promise<void>;
open() : Promise<void>;
close() : Promise<void>;
destroy() : Promise<void>;
clear() : Promise<void>;
db: any;
}
}

View File

@@ -1,41 +0,0 @@
declare module "flexsearch/db/indexeddb" {
type IdType =
"text" |
"char" |
"varchar" |
"string" |
"number" |
"numeric" |
"integer" |
"smallint" |
"tinyint" |
"mediumint" |
"int" |
"int8" |
"uint8" |
"int16" |
"uint16" |
"int32" |
"uint32" |
"int64" |
"uint64" |
"bigint";
type PersistentOptions = {
name?: string;
type?: IdType;
db?: IDBDatabase;
};
export default class StorageInterface {
constructor(name: string, config: PersistentOptions);
constructor(config: string | PersistentOptions);
//mount(index: Index | Document) : Promise<void>;
open() : Promise<void>;
close() : Promise<void>;
destroy() : Promise<void>;
clear() : Promise<void>;
db: IDBDatabase;
}
}

View File

@@ -1,41 +0,0 @@
declare module "flexsearch/db/mongodb" {
type IdType =
"text" |
"char" |
"varchar" |
"string" |
"number" |
"numeric" |
"integer" |
"smallint" |
"tinyint" |
"mediumint" |
"int" |
"int8" |
"uint8" |
"int16" |
"uint16" |
"int32" |
"uint32" |
"int64" |
"uint64" |
"bigint";
type PersistentOptions = {
name?: string;
type?: IdType;
db?: any;
};
export default class StorageInterface {
constructor(name: string, config: PersistentOptions);
constructor(config: string | PersistentOptions);
//mount(index: Index | Document) : Promise<void>;
open() : Promise<void>;
close() : Promise<void>;
destroy() : Promise<void>;
clear() : Promise<void>;
db: any;
}
}

View File

@@ -1,41 +0,0 @@
declare module "flexsearch/db/postgres" {
type IdType =
"text" |
"char" |
"varchar" |
"string" |
"number" |
"numeric" |
"integer" |
"smallint" |
"tinyint" |
"mediumint" |
"int" |
"int8" |
"uint8" |
"int16" |
"uint16" |
"int32" |
"uint32" |
"int64" |
"uint64" |
"bigint";
type PersistentOptions = {
name?: string;
type?: IdType;
db?: any;
};
export default class StorageInterface {
constructor(name: string, config: PersistentOptions);
constructor(config: string | PersistentOptions);
//mount(index: Index | Document) : Promise<void>;
open() : Promise<void>;
close() : Promise<void>;
destroy() : Promise<void>;
clear() : Promise<void>;
db: any;
}
}

View File

@@ -1,41 +0,0 @@
declare module "flexsearch/db/redis" {
type IdType =
"text" |
"char" |
"varchar" |
"string" |
"number" |
"numeric" |
"integer" |
"smallint" |
"tinyint" |
"mediumint" |
"int" |
"int8" |
"uint8" |
"int16" |
"uint16" |
"int32" |
"uint32" |
"int64" |
"uint64" |
"bigint";
type PersistentOptions = {
name?: string;
type?: IdType;
db?: any;
};
export default class StorageInterface {
constructor(name: string, config: PersistentOptions);
constructor(config: string | PersistentOptions);
//mount(index: Index | Document) : Promise<void>;
open() : Promise<void>;
close() : Promise<void>;
destroy() : Promise<void>;
clear() : Promise<void>;
db: any;
}
}

View File

@@ -1,41 +0,0 @@
declare module "flexsearch/db/sqlite" {
type IdType =
"text" |
"char" |
"varchar" |
"string" |
"number" |
"numeric" |
"integer" |
"smallint" |
"tinyint" |
"mediumint" |
"int" |
"int8" |
"uint8" |
"int16" |
"uint16" |
"int32" |
"uint32" |
"int64" |
"uint64" |
"bigint";
type PersistentOptions = {
name?: string;
type?: IdType;
db?: any;
};
export default class StorageInterface {
constructor(name: string, config: PersistentOptions);
constructor(config: string | PersistentOptions);
//mount(index: Index | Document) : Promise<void>;
open() : Promise<void>;
close() : Promise<void>;
destroy() : Promise<void>;
clear() : Promise<void>;
db: any;
}
}