Searching

class xettel.search.Search(reader: ZXReader, query: str, sort: bool = False, n: Optional[int] = None)

The Search class provides an interface for common search operations.

Parameters
  • reader (ZXReader) – a reader for the Xapian database.

  • query (str) – a querystring for Xapian to parse. If the provided query is '*', then rather than searching using Xapian, the whole Zettelkasten is retrieved.

reader

the reader.

Type

ZXReader

query

the query.

Type

str

sort

whether to sort by most recent

Type

bool

n

the number of search results to ouput, `None’ for all the results

Type

Optional[int]

results

a SearchList object corresponding to the query.

Type

SearchList

class xettel.search.SearchList(zk: ZettelkastenAbstract, reader: ZXReader)

The SearchList class provides a way to retreive information from a Xapian search.

Parameters
zettelkastenk

a Zettelkasten

Type

ZettelkastenAbstract

reader

a reader into the Xapian database

Type

ZXReader

get_results() Iterator[xettel.search.SearchResult]

Iterator over the results of the query.

Yields

Results from the query.

map() dict[str, str]

Gives a mapping uid -> filename.

Returns

A dictionnary mapping uids (as string, both in base 10 or in base36) to the corresponding filename.

output(mode: str) str

Provides a string representing the results according to a chosen representation.

Parameters

mode (str) –

A string representing a mode. The modes currently implemented are:

  • normal: gives a summary of each zettel containing its uid, its tags, its title and its abstract.

  • uid: gives the uids in base 36

  • tags: gives the tags appearing in the Zettels

  • filename: gives the filename of each Zettel

  • backlinks: gives the backlinks for each zettel

  • map: gives a json-formatted map as described in SearchList.map

  • json: gives a full json with all info and unexpanded uids

Raises

NotImplementedError – if the mode is one of the above.

Returns

A string whose lines are as described in the specification for the mode argument.

tags() list[str]

Gives the tags that appear in the Zettels matching the query.

Returns

A lexically ordered list with unique elements giving the tags of the zettels.

to_dict() dict[str, dict[str, typing.Any]]

Gives a plain list of the results

Returns

A dict of all the search results, indexed by their base 36 uid, without their text.

class xettel.search.SearchResult(zettel: ZA)

The class SearchResult provides an interface (coded as a MutableMapping) to get results from a Zettel.

The keys currently implemented with a special behaviour are:

  • uid

  • uid36

  • filename

  • backlinks

If they doesn’t belong to the list above, then the value is taken from the Zettel’s attributes dictionnary.

Specification for the special behaviour are explained in the method used to give them.

Parameters

zettel (ZA) – a Zettel

item

a Zettel

Type

ZA

Gives a comma-separated list of the basenames of the Zettel’s backlinks.

Returns

a comma-separated list of the basenames of the Zettel’s backlinks.

Return type

str

filename() str

Gives the filename of the Zettel

Returns

A string with the filename.

format(string: str) str

Takes advantages of the fact that this class is a mutable mapping to format a string with the attributes of the Zettel.

Returns

A formatted string.

Return type

str

normal() str

Gives the default representation of a Zettel.

Returns

abstract”

Return type

A string formatted as “uid36 (#tags) – title

uid36() str

Gives the uid in base 36.

Returns

A string with the uid in base 36.

class xettel.search.SetEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)
default(obj)

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)