dataset

This module implements the Dataset class, which binds a Setting to a sayt2 search index and provides build/search operations.

class afwf_fts_anything.dataset.Dataset(name: str, dir_root: Path)[source]

A search dataset backed by a sayt2 index.

Identified by a name and a dir_root directory that owns all dataset resources under a shared convention:

  • {dir_root}/{name}-setting.json – field schema and display config

  • {dir_root}/{name}-data.json – the records to index

  • {dir_root}/{name}-index/ – sayt2 index directory (auto-created)

  • {dir_root}/icons/{name}.png – per-result icons (resolved on demand)

get_icon(name: str) Path[source]

Return the path to {dir_icons}/{name}.

get_setting() Setting[source]

Load and return the Setting from disk (no cache).

get_data() list[dict][source]

Read records from the local data JSON file.

If the file does not exist, download_data() is called first.

property setting: Setting

Parsed Setting, cached after the first call.

get_sayt2_dataset() DataSet[source]

Create a sayt2.DataSet wired to this dataset’s index and setting.

download_data() None[source]

Download the dataset from Setting.data_url and save it locally.

Raises ValueError if data_url is not configured.

build_index(data: list[dict[str, Any]] | None = None, rebuild: bool = False) int[source]

Build the sayt2 search index from data.

Parameters:
  • data – records to index; if None the configured downloader is used.

  • rebuild – if True, evict the query cache before building so subsequent searches always reflect the new index.

Returns:

number of documents indexed.

search(query: str, limit: int = 20) list[dict[str, Any]][source]

Search the index and return matching documents as plain dicts.

Parameters:
  • query – Lucene-syntax query string.

  • limit – maximum number of results to return.

Returns:

list of hit.source dicts ordered by relevance / sort key.