Permalink
Browse files

Add support for text search configurations, dictionaries and templates.

 * docs/textsearch.rst: Document new text search objects.
 * pyrseas/database.py (Database.Dicts.__init__): Add dictionaries for
   new text search objects.  (Database.link_refs): Add tsconfigs,
   tsdicts and tstempls arguments to schemas.link_refs call.
   (Database.diff_map): Call diff_map's for new text search objects.
 * pyrseas/dbobject/schema.py (Schema.to_map): Process new text search
   objects.  (SchemaDict.from_map): Process new input text search
   objects.  (SchemaDict.link_refs): Add arguments for new text search
   objects.
 * pyrseas/dbobject/textsearch.py: Add classes for new objects.
 * tests/dbobject/test_textsearch.py: Add tests for new objects.
  • Loading branch information...
1 parent e727f43 commit 4577f619a85599fdfc784e6c06d7347238f16c7d @jmafc jmafc committed Nov 28, 2011
Showing with 681 additions and 15 deletions.
  1. +81 −3 docs/textsearch.rst
  2. +10 −2 pyrseas/database.py
  3. +40 −3 pyrseas/dbobject/schema.py
  4. +307 −4 pyrseas/dbobject/textsearch.py
  5. +243 −3 tests/dbobject/test_textsearch.py
View
@@ -3,9 +3,63 @@ Text Search Objects
.. module:: pyrseas.dbobject.textsearch
-The :mod:`textsearch` module defines two classes: class
-:class:`TSParser` derived from :class:`DbSchemaObject` and class
-:class:`TSParserDict` derived from :class:`DbObjectDict`.
+The :mod:`textsearch` module defines eight classes: classes
+:class:`TSConfiguration`, :class:`TSDictionary`, :class:`TSParser` and
+:class:`TSTemplate` derived from :class:`DbSchemaObject`, and classes
+:class:`TSConfigurationDict`, :class:`TSDictionaryDict`,
+:class:`TSParserDict` and :class:`TSTemplateDict` derived from
+:class:`DbObjectDict`.
+
+Text Search Configuration
+-------------------------
+
+:class:`TSConfiguration` is derived from :class:`DbSchemaObject` and
+represents a `PostgreSQL text search configuration
+<http://www.postgresql.org/docs/current/static/sql-createtsconfig.html>`_.
+
+.. autoclass:: TSConfiguration
+
+.. automethod:: TSConfiguration.to_map
+
+.. automethod:: TSConfiguration.create
+
+Text Search Configuration Dictionary
+------------------------------------
+
+:class:`TSConfigurationDict` is derived from
+:class:`~pyrseas.dbobject.DbObjectDict`. It is a dictionary that
+represents the collection of text search configurations in a database.
+
+.. autoclass:: TSConfigurationDict
+
+.. automethod:: TSConfigurationDict.from_map
+
+.. automethod:: TSConfigurationDict.diff_map
+
+Text Search Dictionary
+----------------------
+
+:class:`TSDictionary` is derived from :class:`DbSchemaObject` and
+represents a `PostgreSQL text search dictionary
+<http://www.postgresql.org/docs/current/static/textsearch-dictionaries.html>`_.
+
+.. autoclass:: TSDictionary
+
+.. automethod:: TSDictionary.create
+
+Text Search Dictionary Dictionary
+---------------------------------
+
+:class:`TSDictionaryDict` is derived from
+:class:`~pyrseas.dbobject.DbObjectDict`. It is a Python dictionary
+that represents the collection of text search dictionaries in a
+database.
+
+.. autoclass:: TSDictionaryDict
+
+.. automethod:: TSDictionaryDict.from_map
+
+.. automethod:: TSDictionaryDict.diff_map
Text Search Parser
------------------
@@ -30,3 +84,27 @@ represents the collection of text search parsers in a database.
.. automethod:: TSParserDict.from_map
.. automethod:: TSParserDict.diff_map
+
+Text Search Template
+--------------------
+
+:class:`TSTemplate` is derived from :class:`DbSchemaObject` and
+represents a `PostgreSQL text search template
+<http://www.postgresql.org/docs/current/static/sql-createtstemplate.html>`_.
+
+.. autoclass:: TSTemplate
+
+.. automethod:: TSTemplate.create
+
+Text Search Template Dictionary
+-------------------------------
+
+:class:`TSTemplateDict` is derived from
+:class:`~pyrseas.dbobject.DbObjectDict`. It is a dictionary that
+represents the collection of text search templates in a database.
+
+.. autoclass:: TSTemplateDict
+
+.. automethod:: TSTemplateDict.from_map
+
+.. automethod:: TSTemplateDict.diff_map
View
@@ -25,7 +25,8 @@
from pyrseas.dbobject.rule import RuleDict
from pyrseas.dbobject.trigger import TriggerDict
from pyrseas.dbobject.conversion import ConversionDict
-from pyrseas.dbobject.textsearch import TSParserDict
+from pyrseas.dbobject.textsearch import TSConfigurationDict, TSDictionaryDict
+from pyrseas.dbobject.textsearch import TSParserDict, TSTemplateDict
def flatten(lst):
@@ -64,7 +65,10 @@ def __init__(self, dbconn=None):
self.rules = RuleDict(dbconn)
self.triggers = TriggerDict(dbconn)
self.conversions = ConversionDict(dbconn)
+ self.tstempls = TSTemplateDict(dbconn)
+ self.tsdicts = TSDictionaryDict(dbconn)
self.tsparsers = TSParserDict(dbconn)
+ self.tsconfigs = TSConfigurationDict(dbconn)
def __init__(self, dbconn):
"""Initialize the database
@@ -79,7 +83,8 @@ def _link_refs(self, db):
db.languages.link_refs(db.functions)
db.schemas.link_refs(db.types, db.tables, db.functions, db.operators,
db.operfams, db.operclasses, db.conversions,
- db.tsparsers)
+ db.tsconfigs, db.tsdicts, db.tsparsers,
+ db.tstempls)
db.tables.link_refs(db.columns, db.constraints, db.indexes,
db.rules, db.triggers)
db.types.link_refs(db.columns, db.constraints, db.functions)
@@ -166,7 +171,10 @@ def diff_map(self, input_map):
stmts.append(self.db.triggers.diff_map(self.ndb.triggers))
stmts.append(self.db.rules.diff_map(self.ndb.rules))
stmts.append(self.db.conversions.diff_map(self.ndb.conversions))
+ stmts.append(self.db.tsdicts.diff_map(self.ndb.tsdicts))
+ stmts.append(self.db.tstempls.diff_map(self.ndb.tstempls))
stmts.append(self.db.tsparsers.diff_map(self.ndb.tsparsers))
+ stmts.append(self.db.tsconfigs.diff_map(self.ndb.tsconfigs))
stmts.append(self.db.casts.diff_map(self.ndb.casts))
stmts.append(self.db.operators._drop())
stmts.append(self.db.operclasses._drop())
View
@@ -43,8 +43,8 @@ def mapper(schema, objtypes):
schema[key].update(tbls)
for objtypes in ['conversions', 'domains', 'functions', 'operators',
- 'operclasses', 'operfams', 'sequences', 'tsparsers',
- 'types', 'views']:
+ 'operclasses', 'operfams', 'sequences', 'tsconfigs',
+ 'tsdicts', 'tsparsers', 'tstempls', 'types', 'views']:
schema[key].update(mapper(self, objtypes))
if hasattr(self, 'description'):
@@ -97,7 +97,10 @@ def from_map(self, inmap, newdb):
inopcls = {}
inopfams = {}
inconvs = {}
+ intscs = {}
+ intsds = {}
intsps = {}
+ intsts = {}
for key in inschema.keys():
if key.startswith('domain '):
intypes.update({key: inschema[key]})
@@ -117,8 +120,14 @@ def from_map(self, inmap, newdb):
inopers.update({key: inschema[key]})
elif key.startswith('conversion '):
inconvs.update({key: inschema[key]})
+ elif key.startswith('text search dictionary '):
+ intsds.update({key: inschema[key]})
+ elif key.startswith('text search template '):
+ intsts.update({key: inschema[key]})
elif key.startswith('text search parser '):
intsps.update({key: inschema[key]})
+ elif key.startswith('text search configuration '):
+ intscs.update({key: inschema[key]})
elif key == 'oldname':
schema.oldname = inschema[key]
del inschema['oldname']
@@ -133,10 +142,14 @@ def from_map(self, inmap, newdb):
newdb.operclasses.from_map(schema, inopcls)
newdb.operfams.from_map(schema, inopfams)
newdb.conversions.from_map(schema, inconvs)
+ newdb.tsdicts.from_map(schema, intsds)
+ newdb.tstempls.from_map(schema, intsts)
newdb.tsparsers.from_map(schema, intsps)
+ newdb.tsconfigs.from_map(schema, intscs)
def link_refs(self, dbtypes, dbtables, dbfunctions, dbopers, dbopfams,
- dbopcls, dbconvs, dbtspars):
+ dbopcls, dbconvs, dbtsconfigs, dbtsdicts, dbtspars,
+ dbtstmpls):
"""Connect types, tables and functions to their respective schemas
:param dbtypes: dictionary of types and domains
@@ -146,7 +159,10 @@ def link_refs(self, dbtypes, dbtables, dbfunctions, dbopers, dbopfams,
:param dbopfams: dictionary of operator families
:param dbopcls: dictionary of operator classes
:param dbconvs: dictionary of conversions
+ :param dbtsconfigs: dictionary of text search configurations
+ :param dbtsdicts: dictionary of text search dictionaries
:param dbtspars: dictionary of text search parsers
+ :param dbtstmpls: dictionary of text search templates
Fills in the `domains` dictionary for each schema by
traversing the `dbtypes` dictionary. Fills in the `tables`,
@@ -230,13 +246,34 @@ def link_refs(self, dbtypes, dbtables, dbfunctions, dbopers, dbopfams,
if not hasattr(schema, 'conversions'):
schema.conversions = {}
schema.conversions.update({cnv: conv})
+ for (sch, tsc) in dbtsconfigs.keys():
+ tscfg = dbtsconfigs[(sch, tsc)]
+ assert self[sch]
+ schema = self[sch]
+ if not hasattr(schema, 'tsconfigs'):
+ schema.tsconfigs = {}
+ schema.tsconfigs.update({tsc: tscfg})
+ for (sch, tsd) in dbtsdicts.keys():
+ tsdict = dbtsdicts[(sch, tsd)]
+ assert self[sch]
+ schema = self[sch]
+ if not hasattr(schema, 'tsdicts'):
+ schema.tsdicts = {}
+ schema.tsdicts.update({tsd: tsdict})
for (sch, tsp) in dbtspars.keys():
tspar = dbtspars[(sch, tsp)]
assert self[sch]
schema = self[sch]
if not hasattr(schema, 'tsparsers'):
schema.tsparsers = {}
schema.tsparsers.update({tsp: tspar})
+ for (sch, tst) in dbtstmpls.keys():
+ tstmpl = dbtstmpls[(sch, tst)]
+ assert self[sch]
+ schema = self[sch]
+ if not hasattr(schema, 'tstempls'):
+ schema.tstempls = {}
+ schema.tstempls.update({tst: tstmpl})
def to_map(self):
"""Convert the schema dictionary to a regular dictionary
Oops, something went wrong.

0 comments on commit 4577f61

Please sign in to comment.