Open source cms for mobile and desktop websites

nive.search

This file provides global search functionality, database lookup and sql query wrappers. It is usually attached to root objects.

Search parameter handling

Most functions support a similar parameter handling for generating sql queries.

Parameters  
fields

list of database fields (field ids) to include in result. prefix ‘-‘: special fields or aggregate functions can be inserted by adding

a ‘-‘ in front of the field. -count(*) or -MAX(field1)

prefix ‘+’: special fields skipped in SQL query e.g. ‘+preview’

parameter dictionary with fieldname:value entries used for search conditions
operators dictionary with fieldname:operator entries used for search conditions default: strings=*LIKE*, all others=’=’ possible values: ``=, LIKE, NOT IN, IN, >, <, <=, >=, !=, BETWEEN ``
sort result sort field or list if multiple
ascending sort ascending or decending
start start position in result
max maximum number of result records

Parameter for operator BETWEEN has to be formatted: e.g. ‘2006/10/10’ AND ‘2006/10/11’

Keyword options (Not supported by all functions)
logicalOperator link between conditions. default: AND. possible: AND, OR, NOT
condition custom sql condition statement appended to WHERE clause
groupby used as sql GROUP BY statement
join adds a custom custom sql join statement
jointype left, inner, right. default = inner (used by SearchType())
mapJoinFld fieldname to map title by left/right join (used by SearchType())
addID Add fld.id in query without showing in result list. used for custom columns e.g. -(select ...)
skipRender render result flds as html element. default: pool_type, pool_wfa, pool_wfp to skip all: True, or a list of fields (“pool_wfa”,”pool_type”)
skipCount enable or disable second query to get the number of all records.
relation Resolve a relation and load the related entry as object. For example you load the user object by settings relation=pool_createdby. The result set will include the user object instead of the user name.

Adding custom join statements

“join” = “inner join pool_meta as __parent on __parent.id = meta__.pool_unitref”

fields = [“-__parent.pool_filename as profile_filename”]

Search result (supported by Search*() functions)
criteria dictionary containing parameters used in search
count number of records contained in result
total total number of records matching the query
items result list. each record as dictionary. Each field is rendered for display depending on skipRender keyword. This means list entries are replaced by their readable names, dates are rendered readable.
start record start number in result
max maximum number of records
next start number of next record set
nextend end number of next record set
prev start number of previous record set
prevend end number of previous record set
sql the sql statement used
class nive.search.Search
Select(pool_type=None, parameter=None, fields=None, operators=None, sort=None, ascending=1, start=0, max=0, **kw)

Fast and simple sql query.

If pool_type is not set the query will apply to the meta layer only. In this case you can only include pool_meta.fields in fields. To use a single table pass dataTable as keyword.

If pool_type is set you can use meta and data fields. The query is restricted to a single type.

Supported keywords: groupby, logicalOperator, condition, dontAddType, dataTable

The following example selects all children of the current object

fields = ["id", "title", "pool_type"]
parameter["pool_unitref"] = self.id
records = self.dataroot.Select(parameter=parameter, fields=fields)

returns records as list

SelectDict(pool_type=None, parameter=None, fields=None, operators=None, sort=None, ascending=1, start=0, max=0, **kw)

Fast and simple sql query.

If pool_type is not set the query will apply to the meta layer only. In this case you can only include pool_meta.fields in fields.

If pool_type is set you can use meta and data fields. The query is restricted to a single type.

Supported keywords: groupby, logicalOperator, condition

Records are returned as dictionaries

The following example selects all children not of type image of the current object

fields = ["id", "title", "pool_type"]
parameter = {"pool_unitref": self.id}
operators = {"pool_type": "!="}
records = self.dataroot.SelectDict("image", 
                                   parameter=parameter, 
                                   fields=fields, 
                                   operators=operators)

returns records as dict list

Search(parameter, fields=None, operators=None, **kw)

Extended meta layer search function. Supports all keyword options and search result.

Example

root.()Search({"title":"test"}, 
              fields=["id", "pool_type", "title"], 
              start=0, max=50, 
              operators={"title":"="})

returns search result (See above)

SearchType(pool_type, parameter, fields=None, operators=None, **kw)

Extended meta and data layer search function. Supports all keyword options and search result.

Example

root.()SearchType("image", 
                  parameter={"title":"test"}, 
                  fields=["id", "pool_type", "title"], 
                  start=0, max=50, 
                  operators={"title":"="})

returns search result (See above)

SearchData(pool_type, parameter, fields=None, operators=None, **kw)

Extended data layer search function. Supports all keyword options and search result.

Example

root.()SearchData("image", 
                  parameter={"text": "new"}, 
                  fields=["id", "text", "title"], 
                  start=0, max=50, 
                  operators={"text":"LIKE"})

returns search result (See above)

SearchFulltext(phrase, parameter=None, fields=None, operators=None, **kw)

Fulltext search function. Searches all text fields marked for fulltext search. Uses searchPhrase as parameter for text search. Supports all keyword options and search result.

Example

root().SearchFulltext("new", parameter={}, 
                  fields=["id", "title"], 
                  start=0, max=50, 
                  operators={"text":"LIKE"})

returns search result (See above)

SearchFulltextType(pool_type, phrase, parameter=None, fields=None, operators=None, **kw)

Fulltext search function. Searches all text fields marked for fulltext search of the given type. Uses searchPhrase as parameter for text search. Supports all keyword options and search result.

Example

root.()SearchFulltextType("text",
                  parameter={"searchPhrase": "new"}, 
                  fields=["id", "text", "title"], 
                  start=0, max=50, 
                  operators={"text":"LIKE"})

returns search result (See above)

SearchFilename(filename, parameter, fields=None, operators=None, **kw)

Filename search function. Searches all physical file filenames (not url path names). Supports all keyword options and search result.

Includes matchinng files as “result_files” in each record.

Example

root.()SearchFulltextType("text",
                  parameter={"searchPhrase": "new"}, 
                  fields=["id", "text", "title"], 
                  start=0, max=50, 
                  operators={"text":"LIKE"})

returns search result (See above)

GetTree(flds=None, sort=u'id', base=0, parameter=u'')

Select list of all folders from db.

returns the subtree {‘items’: [{u’id’: 354956L, ‘ref1’: 354954L, ‘ref2’: 354952L, ..., ‘ref10’: None, ‘items’: [...]}]

TreeParentIDs(id)

returns the parent ids for the object with id as list

TreeParentTitles(id)

returns the parent titles for the object with id as list

GetEntriesAsCodeList(pool_type, name_field, parameter=None, operators=None, sort=None)

Search the database for entries of type pool_type and return matches as codelist

[{"name": name_field, "id": object.id}, ... ]

If the name_field is stored as data field, insert data. at the beginning of name_field (e.g. data.header)

returns list

GetEntriesAsCodeList2(name_field, parameter=None, operators=None, sort=None)

Search the database and return matches as codelist

[{"name": name_field, "id": object.id}, ... ]

returns list

GetGroupAsCodeList(pool_type, name_field, parameter=None, operators=None, sort=None)

Search the database for entries of type pool_type and return matches grouped by unique name_field values as codelist

[{"name": name_field, "id": object.id}, ... ]

If the name_field is stored as data field, insert data. at the beginning of name_field (e.g. data.header)

returns list

GetGroupAsCodeList2(name_field, parameter=None, operators=None, sort=None)

Search the database and return matches grouped by unique name_field values as codelist

[{"name": name_field, "id": object.id}, ... ]

returns list

FilenameToID(filename, unitref=None, parameter=None, firstResultOnly=True, operators=None)

Convert url path filename (meta.pool_filename) to id. This function does not lookup physical files and their filenames.

returns id

IDToFilename(id)

Convert id to url path filename (meta.pool_filename). This function does not lookup physical files and their filenames.

returns string

ConvertDatarefToID(pool_type, dataref)

Search for object id based on dataref and pool_type.

returns id

GetMaxID()

Lookup id of the last created object.

returns id

GetReferences(unitID, types=None, sort=u'id')

Search for references in unit or unitlist fields of all objects.

returns id list

LoadListItems(fieldconf, obj=None, pool_type=None, force=False)

bw 0.9.12 LoadListItems moved to nive.helper

© 2013 Nive GmbH