API Docs: Search Functions

class ogitm.gitdb.search_functions.SearchFunction[source]

A list of all search functions.

To add a function, use the SearchFunction.add() decorator. This passes the function itself through (so multiple invocations of the add decorator can be called on the same item), and appends it to the internal store of search functions.

To get a function, use the SearchFunction.get() classmethod. This returns the function described by the given name, or raises KeyError if no function is available.

This class should basically be used as a singleton instance - all methods are class methods, and operate on a shared store of data. This probably isn’t best practice, but it works for now.

See SearchFunction.add() for details on what a search function should actually look like.

classmethod add(*funcnames)[source]

Add a function to the current list of functions.

The function should have the following signature:

Parameters:
  • key (any) – The key for which a value should be found. This is usually not important - the function is also passed the index that pertains to this particular key.
  • operator (str) – The operator/name that this function has been called under. Sometimes it is simpler if different operators all map to the same function (for example, all string methods map to one function that dynamically calls the method on a string instance). This can be then used to work out the specific operation.
  • argument (any) – The argument passed to this particular operator.
  • index (dict[any: list[id]]) – The index related to the key being searched against. This is basically a dict mapping every value that has been assigned to this key to a list of the ids of the documents where this key-value mapping exists.
  • all (set[id]) – The set of all ids that are currently stored. This is useful in the case where you want to search for, say, non-existance of a key, in which case the set of ids that should be returned is the set of all ids that aren’t in the index that the function has been passed.