コード例 #1
0
    def clear(self):
        self.tag_container = SearchByTagContainer(self)
        self.catalog = Catalog()
        self.catalog['tags'] = KeywordIndex('tags', ITagged)
        self.catalog['name'] = TextIndex('display_name', IDisplayName, True)
        self.catalog['__all'] = TextIndex('tokens', ITokenized, True)

        self.ids = IntIds()
コード例 #2
0
    def _createCatalog(self, site):
        """Create the catalog if needed and return it.

        If the catalog already exists, return that.
        """
        catalog = zope.component.queryUtility(
            ICatalog, name=self.catalog_name, context=site, default=None)
        if catalog is not None:
            return catalog
        catalog = Catalog()
        setupUtility(site, catalog, ICatalog, name=self.catalog_name)
        return catalog
コード例 #3
0
def setupCatalog(test, optCount=10, unoptCount=10, halfCount=10):
    intids = IntIds()
    component.provideUtility(intids, IIntIds)
    component.provideAdapter(SimpleKeyReference)
    cat = Catalog()

    cat['opt_name'] = FieldIndex('name', IOptimizedClass)
    cat['opt_value'] = FieldIndex('value', IOptimizedClass)

    cat['half_name'] = FieldIndex('name', IHalfOptimizedClass)
    cat['half_valueOpt'] = FieldIndex('value', IHalfOptimizedClass)

    cat['all_opt'] = AllIndex(IOptimizedClass)
    cat['all_unopt'] = AllIndex(IUnOptimizedClass)
    cat['all_half'] = AllIndex(IHalfOptimizedClass)

    for i in range(optCount):
        o = OptimizedClass()
        o.value = i
        o.name = unicode(i)
        id = intids.register(o)
        cat.index_doc(id, o)

    for i in range(unoptCount):
        o = UnOptimizedClass()
        o.value = i
        o.name = unicode(i)
        id = intids.register(o)
        cat.index_doc(id, o)

    for i in range(halfCount):
        o = HalfOptimizedClass()
        o.valueOpt = i
        o.valueNoOpt = i
        o.name = unicode(i)
        id = intids.register(o)
        cat.index_doc(id, o)

    component.provideUtility(cat, ICatalog, name='foo-catalog')
コード例 #4
0
class SearchContainer(ReadonlyContainer):
    __name__ = 'search'

    def __init__(self):
        self.clear()

    def clear(self):
        self.tag_container = SearchByTagContainer(self)
        self.catalog = Catalog()
        self.catalog['tags'] = KeywordIndex('tags', ITagged)
        self.catalog['name'] = TextIndex('display_name', IDisplayName, True)
        self.catalog['__all'] = TextIndex('tokens', ITokenized, True)

        self.ids = IntIds()

    def index_object(self, obj):
        real_obj = follow_symlinks(obj)
        try:
            self.catalog.index_doc(self.ids.register(real_obj), real_obj)
        except NotYet:
            log.msg("cannot index object %s because it's not yet committed" % obj, system='search')

    def _index_object(self, obj):
        real_obj = follow_symlinks(obj)
        self.catalog.index_doc(self.ids.register(real_obj), real_obj)

    def unindex_object(self, obj):
        try:
            self.catalog.unindex_doc(self.ids.register(obj))
        except NotYet:
            log.msg("cannot unindex object %s because it's not yet committed" % obj, system='search')

    def search(self, **kwargs):
        # HACK, we should be able to setup a persistent utility
        provideUtility(self.ids, IIntIds)
        return list(self.catalog.searchResults(**kwargs))

    def search_goog(self, query):
        # hack, zope catalog treats ':' specially
        return self.search(__all=query.replace(':', '_'))

    @property
    def _items(self):
        return {'by-tag': self.tag_container}
コード例 #5
0
ファイル: utils_opt.py プロジェクト: agroszer/ocql
def setupCatalog(test, optCount=10, unoptCount=10, halfCount=10):
    intids = IntIds()
    component.provideUtility(intids, IIntIds)
    component.provideAdapter(SimpleKeyReference)
    cat = Catalog()

    cat['opt_name'] = FieldIndex('name', IOptimizedClass)
    cat['opt_value'] = FieldIndex('value', IOptimizedClass)

    cat['half_name'] = FieldIndex('name', IHalfOptimizedClass)
    cat['half_valueOpt'] = FieldIndex('value', IHalfOptimizedClass)

    cat['all_opt'] = AllIndex(IOptimizedClass)
    cat['all_unopt'] = AllIndex(IUnOptimizedClass)
    cat['all_half'] = AllIndex(IHalfOptimizedClass)

    for i in range(optCount):
        o = OptimizedClass()
        o.value = i
        o.name = unicode(i)
        id = intids.register(o)
        cat.index_doc(id, o)

    for i in range(unoptCount):
        o = UnOptimizedClass()
        o.value = i
        o.name = unicode(i)
        id = intids.register(o)
        cat.index_doc(id, o)

    for i in range(halfCount):
        o = HalfOptimizedClass()
        o.valueOpt = i
        o.valueNoOpt = i
        o.name = unicode(i)
        id = intids.register(o)
        cat.index_doc(id, o)

    component.provideUtility(cat, ICatalog, name='foo-catalog')
コード例 #6
0
ファイル: utils.py プロジェクト: bendavis78/zope
def setupCatalog(test):
    intids = IntIds()
    component.provideUtility(intids, IIntIds)
    component.provideAdapter(SimpleKeyReference)
    cat = Catalog()

    cat['org_name'] = FieldIndex('name', IOrganization)

    cat['proj_name'] = FieldIndex('name', IProject)
    cat['proj_descr'] = FieldIndex('description', IProject)

    cat['student_name'] = FieldIndex('name', IStudent)
    cat['student_country'] = FieldIndex('country', IStudent)

    cat['mentor_name'] = FieldIndex('name', IMentor)

    cat['all_students'] = AllIndex(IStudent)
    cat['all_mentors'] = AllIndex(IMentor)
    cat['all_projects'] = AllIndex(IProject)
    cat['all_orgs'] = AllIndex(IOrganization)

    m1 = Mentor(u"John Doe")
    id = intids.register(m1)
    cat.index_doc(id, m1)

    p1 = Project(u"Save the world", u'test')
    id = intids.register(p1)
    cat.index_doc(id, p1)

    s1 = Student(u"Charith", u"Sri Lanka")
    id = intids.register(s1)
    cat.index_doc(id, s1)

    s2 = Student(u"Jane", u"USA")
    id = intids.register(s2)
    cat.index_doc(id, s2)

    s3 = Student(u"Ann", u"Hungary")
    id = intids.register(s3)
    cat.index_doc(id, s3)

    s4 = Student(u"Stewart", u"Hungary", m1)
    id = intids.register(s4)
    cat.index_doc(id, s4)

    o1 = Organization(u"Zope.org")
    id = intids.register(o1)
    cat.index_doc(id, o1)

#    cat2 = zc.relation.catalog.Catalog(dumpRelation, loadRelation)
#    cat2.addValueIndex(IProjectRelation['project'], dumpObj, loadObj, btree=BTrees.family32.OO)
#    cat2.addValueIndex(IProjectRelation['mentor'], dumpObj, loadObj, btree=BTrees.family32.OO)
#    cat2.addDefaultQueryFactory(zc.relation.queryfactory.TransposingTransitive('project','mentor'))
#
#    rel = ProjectRelation(m1, p1)
#    cat2.index(rel)
#    component.provideUtility(cat2, zc.relation.interfaces.ICatalog, name='rel-catalog')
    component.provideUtility(cat, ICatalog, name='foo-catalog')
コード例 #7
0
        self.id = id
        self.f1 = f1
        self.f2 = f2
        self.f3 = f3
        self.f4 = f4
        self.t1 = t1
        self.t2 = t2
    def __cmp__(self, other):
        return cmp(self.id, other.id)
    
from zope import interface
import zope.app.intid.interfaces
from zope.app.testing import ztapi
from zope.app.catalog.interfaces import ICatalog
from zope.app.catalog.catalog import Catalog
catalog = Catalog()
ztapi.provideUtility(ICatalog, catalog, 'catalog1')

from zope import interface
import zope.app.intid.interfaces
from zope.app.testing import ztapi
class DummyIntId(object):
    interface.implements(zope.app.intid.interfaces.IIntIds)
    MARKER = '__dummy_int_id__'
    def __init__(self):
        self.counter = 0
        self.data = {}
    def register(self, obj):
        intid = getattr(obj, self.MARKER, None)
        if intid is None:
            setattr(obj, self.MARKER, self.counter)