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
- results
a SearchList object corresponding to the query.
- Type
- class xettel.search.SearchList(zk: ZettelkastenAbstract, reader: ZXReader)
The SearchList class provides a way to retreive information from a Xapian search.
- Parameters
zk (ZettelkastenAbstract) – a Zettelkasten
reader (ZXReader) – a reader into the Xapian database
- zettelkastenk
a Zettelkasten
- Type
- 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.
- 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
- backlinks(zk: ZettelkastenAbstract) str
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
- 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
- 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 aTypeError
).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)