1.2. active_document.database

class active_document.database.Database

Manage Xapian databases.

flush_timeout

Force a flush after flush_timeout seconds since the last change to the database. Needs to be overridden in chile classes.

flush_threshold

Force a flush every flush_threshold changes to the database. Needs to be overridden in chile classes

properties

Property objects collected for a class inherited from the Database

name

Xapian database name.

close()

Close the database.

create(props)

Create new document.

Parameters:props – document properties
Returns:GUID of newly created document
update(guid, props)

Update properties of existing document.

Parameters:
  • guid – document GUID to update
  • props – properties to update, not necessary all document properties
delete(guid)

Delete document.

Props guid:document GUID to delete
find(offset=0, limit=None, request=None, query='', reply=None, order_by=None, group_by=None)

Search documents.

The result will be an array of dictionaries with found documents’ properties.

Parameters:
  • offset – the resulting list should start with this offset; 0 by default
  • limit – the resulting list will be at least limit size; all entries by default
  • request – a dictionary with property values to restrict the search
  • query – a string in Xapian serach format, empty to avoid text search
  • reply – an array of property names to use only in the resulting list; only GUID property will be used by default
  • order_by – array of properties to sort resulting list; property names might be prefixed with + (or without any prefixes) for ascending order, and - for descending order
  • group_by – a property name to group resulting list by; if was specified, every resulting list item will contain grouped with a number of entries that are represented by the current one; no groupping by default
Returns:

a tuple of (entries, total_count); where the total_count is the total number of documents conforming the search parameters, i.e., not only documents that are included to the resulting list

scan_cb()

Scan for a document.

This function will be called from internals when database needs to be populated. If function returns a found document, it will be called once more until it fails.

Returns:None if there no documents; a tuple of (guid, properties) for found document
class active_document.database.Property(name, slot, prefix=None, default=None, boolean=False, multiple=False, separator=None)

Collect inforamtion about document property.

Parameters:
  • name – property name
  • slot – document’s slot number to add property value to; if None, property is not a Xapian value
  • prefix – serach term prefix; if None, property is not a search term
  • default – default property value to use while creating new documents
  • boolean – if prefix is not None, this argument specifies will Xapian use boolean search for that property or not
  • multiple – should property value be treated as a list of words
  • separator – if multiple set, this will be a separator; otherwise any space symbols will be used to separate words
name

Property name.

slot

Xapian document’s slot number to add property value to.

prefix

Xapian serach term prefix, if None, property is not a term.

boolean

Xapian will use boolean search for this property.

default

Default property value or None.

list_value(value)

If property value contains several values, list them all.

Previous topic

1.1. active_document.env

Next topic

2. How to contribute

This Page