[Checkins] SVN: Sandbox/luciano/kirbi/src/kirbi/pac.py catch
ParseError exception in searchResults call
Luciano Ramalho
luciano at ramalho.org
Tue Aug 14 20:38:40 EDT 2007
Log message for revision 78825:
catch ParseError exception in searchResults call
Changed:
U Sandbox/luciano/kirbi/src/kirbi/pac.py
-=-
Modified: Sandbox/luciano/kirbi/src/kirbi/pac.py
===================================================================
--- Sandbox/luciano/kirbi/src/kirbi/pac.py 2007-08-14 22:43:16 UTC (rev 78824)
+++ Sandbox/luciano/kirbi/src/kirbi/pac.py 2007-08-15 00:38:39 UTC (rev 78825)
@@ -4,6 +4,7 @@
from zope.app.container.interfaces import INameChooser
from zope.interface import implements
from zope.lifecycleevent import modified, Attributes
+from zope.index.text import parsetree
from zope import schema
from operator import attrgetter
from isbn import isValidISBN, isValidISBN10, convertISBN10toISBN13, filterDigits
@@ -13,6 +14,8 @@
from persistent.dict import PersistentDict
from time import localtime, strftime
+USER_FOLDER_NAME = u'u'
+
class Pac(grok.Container):
"""Pac (public access catalog)
@@ -105,6 +108,19 @@
class Index(grok.View):
+ def menu_items(self):
+ return [
+ {'url':self.url(self.context.__parent__[USER_FOLDER_NAME],'join'),
+ 'text':u'join'},
+ {'url':'''http://circulante.incubadora.fapesp.br/''',
+ 'text':u'about'},
+ ]
+
+ def coverUrl(self, book):
+ cover_name = 'covers/large/'+book.isbn13+'.jpg'
+ return self.static.get(cover_name,
+ self.static['covers/small-placeholder.jpg'])()
+
def update(self, query=None):
if not query:
# XXX: if the query is empty, return all books; this should change
@@ -124,7 +140,17 @@
isbn = convertISBN10toISBN13(isbn)
results = catalog.searchResults(isbn13=(isbn,isbn))
else:
- results = catalog.searchResults(searchableText=query)
+ try:
+ results = catalog.searchResults(searchableText=query)
+ except parsetree.ParseError:
+ # XXX: ParseError: Query contains only common words: u'as'
+ # this error message means that there is a stop words list
+ # somewhere that is used by zope/index/text/queryparser.py
+ # Stop words are considered harmful, we need to weed
+ # them out - LR
+ self.results_title = u'"%s" is not a valid query' % query
+ self.results = []
+ return
# Note: to sort the results, we must cast the result iterable
# to a list, which can be very expensive
results = list(results)
@@ -142,10 +168,6 @@
self.results = sorted(results, key=attrgetter('filing_title'))
- def coverUrl(self, book):
- cover_name = 'covers/large/'+book.isbn13+'.jpg'
- return self.static.get(cover_name,
- self.static['covers/small-placeholder.jpg'])()
class AddBook(grok.AddForm):
More information about the Checkins
mailing list