Ignore:
Timestamp:
5 Jan 2010, 09:50:36 (15 years ago)
Author:
uli
Message:

Use catalog methods to get search results.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-layout/src/waeup/browser/pages.py

    r4661 r4667  
    66from hurry.query.query import Query, Text
    77from waeup.browser import WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage
     8from waeup.catalog import search, search_context
    89from waeup.interfaces import (IUniversity, IWAeUPObject, IUserContainer,
    910                              IUserAccount, IFacultyContainer)
     
    199200        self.search_result = []
    200201        if query is not None:
    201             self.search_result = self.search_context(query)
     202            self.search_result = search_context(query)
    202203            print "RESULT: ", list(self.search_result)
    203204
    204     def search_context(self, query):
    205         result = Query().searchResults(
    206             Eq(('students_catalog', 'name'), query)
    207             )
    208         return result
    209 
    210 from zope.interface import Interface
    211 from zope import schema
    212 
    213 class IQueryResultItem(Interface):
    214      url = schema.TextLine(
    215           title = u'URL that links to the found item')
    216      title = schema.TextLine(
    217           title = u'Title displayed in search results.')
    218      description = schema.Text(
    219           title = u'Longer description of the item found.')
    220      
    221      
    222 class QueryResultItem(object):
    223      grok.implements(IQueryResultItem)
    224      url = None
    225      title = None
    226      description = None
    227      
    228      def __init__(self, context, view):
    229           self.context = context
    230           self.url = view.url(context)
    231           self.title = context.title
    232           self.description = ''
    233      
    234 class CourseQueryResultItem(QueryResultItem):
    235      def __init__(self, context, view):
    236           self.context = context
    237           self.url = view.url(context)
    238           self.title = "COURSE: " + context.title
    239           self.description = 'code: %s' % context.code
    240 
    241 
    242 #from waeup.viewlets import Search, MainArea
    243 from hurry.query.query import Query, Text, Eq
    244 from zope.app.catalog.interfaces import ICatalog
    245205
    246206class SearchPage(WAeUPPage):
     
    251211
    252212     def update(self, *args, **kw):
    253           #print "UPDATE: ", args, kw
    254           #print self.request.form
    255213          form = self.request.form
    256214          self.hitlist = []
     
    260218          query = form['query']
    261219          self.query = query
    262           cat = getUtility(ICatalog, name='courses_catalog')
    263           #print "CODES: ",  cat['code'].documentCount()
    264           #print "TITLES: ", cat['title'].documentCount()
    265           results = list(cat.searchResults(code=(query, query)))#
    266           #title=(query, query)))
    267           hitlist = []
    268           results = Query().searchResults(
    269                Eq(('courses_catalog', 'code'), query))
    270           for result in results:
    271                hitlist.append(CourseQueryResultItem(result, view=self))
    272 
    273           results = Query().searchResults(
    274                Text(('courses_catalog', 'title'), query))
    275          
    276           for result in results:
    277                hitlist.append(CourseQueryResultItem(result, view=self))
    278 
    279           self.hitlist = hitlist
     220          self.hitlist = search(query=self.query, view=self)
     221          return
    280222
    281223
Note: See TracChangeset for help on using the changeset viewer.