Changeset 4662
- Timestamp:
- 4 Jan 2010, 22:49:01 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-layout/src/waeup/catalog.py
r4485 r4662 73 73 index = cat['code'] 74 74 index.index_doc(intids.getId(obj), obj) 75 76 77 from zope.interface import Interface78 from zope import schema79 80 class IQueryResultItem(Interface):81 url = schema.TextLine(82 title = u'URL that links to the found item')83 title = schema.TextLine(84 title = u'Title displayed in search results.')85 description = schema.Text(86 title = u'Longer description of the item found.')87 88 89 class QueryResultItem(object):90 grok.implements(IQueryResultItem)91 url = None92 title = None93 description = None94 95 def __init__(self, context, view):96 self.context = context97 self.url = view.url(context)98 self.title = context.title99 self.description = ''100 101 class CourseQueryResultItem(QueryResultItem):102 def __init__(self, context, view):103 self.context = context104 self.url = view.url(context)105 self.title = "COURSE: " + context.title106 self.description = 'code: %s' % context.code107 108 109 from waeup.viewlets import Search, MainArea110 from hurry.query.query import Query, Text, Eq111 112 class SearchViewlet(grok.Viewlet):113 grok.viewletmanager(MainArea)114 grok.view(Search)115 grok.context(University)116 117 def update(self, *args, **kw):118 #print "UPDATE: ", args, kw119 #print self.request.form120 form = self.request.form121 self.hitlist = []122 self.query = ''123 if not 'query' in form:124 return125 query = form['query']126 self.query = query127 cat = getUtility(ICatalog, name='courses_catalog')128 #print "CODES: ", cat['code'].documentCount()129 #print "TITLES: ", cat['title'].documentCount()130 results = list(cat.searchResults(code=(query, query)))#131 #title=(query, query)))132 hitlist = []133 results = Query().searchResults(134 Eq(('courses_catalog', 'code'), query))135 for result in results:136 hitlist.append(CourseQueryResultItem(result, view=self.view))137 138 results = Query().searchResults(139 Text(('courses_catalog', 'title'), query))140 141 for result in results:142 hitlist.append(CourseQueryResultItem(result, view=self.view))143 144 self.hitlist = hitlist
Note: See TracChangeset for help on using the changeset viewer.