Changeset 4666 for waeup/branches/ulif-layout/src
- Timestamp:
- 5 Jan 2010, 09:49:56 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-layout/src/waeup/catalog.py
r4664 r4666 58 58 index = cat['code'] 59 59 index.index_doc(intids.getId(obj), obj) 60 61 from zope.interface import Interface 62 from zope import schema 63 64 class IQueryResultItem(Interface): 65 url = schema.TextLine( 66 title = u'URL that links to the found item') 67 title = schema.TextLine( 68 title = u'Title displayed in search results.') 69 description = schema.Text( 70 title = u'Longer description of the item found.') 71 72 73 class QueryResultItem(object): 74 grok.implements(IQueryResultItem) 75 url = None 76 title = None 77 description = None 78 79 def __init__(self, context, view): 80 self.context = context 81 self.url = view.url(context) 82 self.title = context.title 83 self.description = '' 84 85 class CourseQueryResultItem(QueryResultItem): 86 def __init__(self, context, view): 87 self.context = context 88 self.url = view.url(context) 89 self.title = "COURSE: " + context.title 90 self.description = 'code: %s' % context.code 91 92 def search(query=None, view=None): 93 if not query: 94 return [] 95 cat = getUtility(ICatalog, name='courses_catalog') 96 results = list(cat.searchResults(code=(query, query))) 97 98 hitlist = [] 99 results = Query().searchResults( 100 Eq(('courses_catalog', 'code'), query)) 101 for result in results: 102 hitlist.append(CourseQueryResultItem(result, view=view)) 103 104 results = Query().searchResults( 105 Text(('courses_catalog', 'title'), query)) 106 107 for result in results: 108 hitlist.append(CourseQueryResultItem(result, view=view)) 109 110 return hitlist 111 112 def search_context(query): 113 result = Query().searchResults( 114 Eq(('students_catalog', 'name'), query) 115 ) 116 return result
Note: See TracChangeset for help on using the changeset viewer.