Index searchable content¶
import {
SearchableTextFieldset, SearchableTextProcessor
} from '@phfaist/zoodb/dbprocessor/searchabletext';
import {
FLMSearchableDocTextValuesAssembler
} from '@phfaist/zoodb/dbprocessor/searchabletextflm';
- class SearchableTextFieldset()¶
Describes the set of searchable text fields that will be extracted from zoo objects and assembled into a flat search document per object.
Configuration options (config argument):
field_name_id — the key used for the object’s ID in the search document (default: ‘id’).
field_name_title — the key used for the object’s title/name in the search document (default: ‘title’).
assemble_doc_text_values — a function
(doc_values: Array<[key, value]>) → Objectthat converts the raw list of[key, value]pairs into a flat key→string document. Defaults to a built-in function that concatenates multiple values for the same key with newlines. Replace this with anFLMSearchableDocTextValuesAssembler()instance’s assemble_doc_text_values method when FLM content is present.searchable_text_fieldset_name — the property name set on
obj._zoodbto store the assembled search document (default: ‘searchable_text_doc’).object_types — array of object type names to include; defaults to all types registered in the ZooDb instance.
exclude_fields — an array of field names to exclude from the search index even if their schema would normally include them.
- SearchableTextFieldset.SearchableTextFieldset¶
- class SearchableTextProcessor(searchable_text_fieldset)¶
Database processor that builds a flat searchable-text document for every object in the zoo and stores it in
obj._zoodb.<fieldset_name>.The shape of the generated documents is determined by the
SearchableTextFieldset()passed to the constructor. Once built, the documents can be fed into a client-side search library such as Lunr.js.- Arguments:
searchable_text_fieldset (SearchableTextFieldset) – Configured fieldset that controls which object fields are included in the search document and how they are assembled.
- SearchableTextProcessor.SearchableTextProcessor¶
- SearchableTextProcessor.process_data_dump(data, options)¶
Prepare a data dump by optionally stripping the generated search documents from the objects.
The single recognised option is searchabletext_remove_doc_info (default true): when true, obj._zoodb.<fieldset_name> is deleted from every object before the dump, reducing payload size. Set it to false to retain the search documents in the exported data.
- Arguments:
data (Object) – The data object being assembled for the dump.
options (Object) – Dump options; see above.
- Returns:
Promise.<Object> – The (mutated) data object.
- class FLMSearchableDocTextValuesAssembler()¶
Assembles search-document values from a list of
[key, value]pairs where some values may be compiled FLM fragments. Each fragment is rendered to plain text inside an FLM document context so that citations and cross-references resolve correctly.Pass an instance’s assemble_doc_text_values method as the assemble_doc_text_values option of
SearchableTextFieldset()when zoo objects contain FLM-formatted fields.Constructor parameters:
zoo_flm_environment (required) — the FLM environment used to create the rendering document.
render_value_fn — function called as
render_value_fn(v, render_context)to convert a single field value to a string. Defaults to the render_value helper from zooflm.doc_metadata — metadata object forwarded to zoo_flm_environment.make_document(). Defaults to null.
text_fragment_renderer — fragment renderer used to produce plain text. Defaults to a new
ZooTextFragmentRenderer()instance.
- FLMSearchableDocTextValuesAssembler.FLMSearchableDocTextValuesAssembler¶