Changeset 4475 for waeup/branches
- Timestamp:
- 28 Jul 2009, 15:37:25 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/catalog.py
r4472 r4475 42 42 43 43 code = index.Field(attribute='code') 44 title = index. Field(attribute='title')44 title = index.Text(attribute='title') 45 45 46 46 … … 67 67 index = cat['code'] 68 68 index.index_doc(intids.getId(obj), obj) 69 70 71 from zope.interface import Interface 72 from zope import schema 73 74 class IQueryResultItem(Interface): 75 url = schema.TextLine( 76 title = u'URL that links to the found item') 77 title = schema.TextLine( 78 title = u'Title displayed in search results.') 79 description = schema.Text( 80 title = u'Longer description of the item found.') 81 82 83 class QueryResultItem(object): 84 grok.implements(IQueryResultItem) 85 url = None 86 title = None 87 description = None 88 89 def __init__(self, context, view): 90 self.context = context 91 self.url = view.url(context) 92 self.title = context.title 93 self.description = '' 94 95 class CourseQueryResultItem(QueryResultItem): 96 def __init__(self, context, view): 97 self.context = context 98 self.url = view.url(context) 99 self.title = "COURSE: " + context.title 100 self.description = 'code: %s' % context.code 101 102 103 from waeup.viewlets import Search, MainArea 104 from hurry.query.query import Query, Text, Eq 105 106 class SearchViewlet(grok.Viewlet): 107 grok.viewletmanager(MainArea) 108 grok.view(Search) 109 grok.context(University) 110 111 def update(self, *args, **kw): 112 #print "UPDATE: ", args, kw 113 #print self.request.form 114 form = self.request.form 115 self.hitlist = [] 116 self.query = '' 117 if not 'query' in form: 118 return 119 query = form['query'] 120 self.query = query 121 cat = getUtility(ICatalog, name='courses_catalog') 122 #print "CODES: ", cat['code'].documentCount() 123 #print "TITLES: ", cat['title'].documentCount() 124 results = list(cat.searchResults(code=(query, query)))# 125 #title=(query, query))) 126 hitlist = [] 127 results = Query().searchResults( 128 Eq(('courses_catalog', 'code'), query)) 129 for result in results: 130 hitlist.append(CourseQueryResultItem(result, view=self.view)) 131 132 results = Query().searchResults( 133 Text(('courses_catalog', 'title'), query)) 134 135 for result in results: 136 hitlist.append(CourseQueryResultItem(result, view=self.view)) 137 138 self.hitlist = hitlist
Note: See TracChangeset for help on using the changeset viewer.