jump to first page for new searches, or if o not in range, fix highlightText

This commit is contained in:
j 2007-04-06 19:19:41 +00:00
parent 36dfdcaa50
commit 5c247d77ed
4 changed files with 18 additions and 5 deletions

View file

@ -259,6 +259,8 @@ class Root(controllers.RootController):
if v == 'quote': if v == 'quote':
tg_template = ".templates.quoteview" tg_template = ".templates.quoteview"
if f != 'all' and s == 'relevance':
s='title'
orderBy = [self.get_sort(s), 'title_sort', 'rel_date'] orderBy = [self.get_sort(s), 'title_sort', 'rel_date']
if q: if q:
q = q.encode('utf-8') q = q.encode('utf-8')
@ -273,11 +275,13 @@ class Root(controllers.RootController):
sort = sort[1:] sort = sort[1:]
sort = self._search_map.get(sort, sort) sort = self._search_map.get(sort, sort)
sort = self._sort_map.get(sort, sort) sort = self._sort_map.get(sort, sort)
print sort
if type(items) == list: if type(items) == list:
search['length'] = len(items) search['length'] = len(items)
else: else:
search['length'] = items.count() search['length'] = items.count()
if o > search['length']:
o = 0
search['o'] = 0
cherrypy.session['search'] = search cherrypy.session['search'] = search
return dict(items = items[o:o+n], sort = sort, search = search, tg_template = tg_template) return dict(items = items[o:o+n], sort = sort, search = search, tg_template = tg_template)

View file

@ -63,6 +63,7 @@ class ArchiveItem(SQLObject):
ALTER TABLE archive_item ADD FULLTEXT (title, description, text); ALTER TABLE archive_item ADD FULLTEXT (title, description, text);
ALTER TABLE archive_item CHANGE size size bigint; ALTER TABLE archive_item CHANGE size size bigint;
ALTER TABLE archive_item CHANGE html html longtext; ALTER TABLE archive_item CHANGE html html longtext;
ALTER TABLE archive_item CHANGE description description longtext;
ALTER TABLE archive_item CHANGE text text longtext; ALTER TABLE archive_item CHANGE text text longtext;
''' '''
hashId = UnicodeCol(alternateID = True, length=128) hashId = UnicodeCol(alternateID = True, length=128)

View file

@ -20,7 +20,7 @@ function submitFind() {
var s = document.getElementById('selectSort').value; var s = document.getElementById('selectSort').value;
var f = document.getElementById('selectFind').value; var f = document.getElementById('selectFind').value;
var q = document.getElementById('inputFind').value; var q = document.getElementById('inputFind').value;
document.location.href = '/search?l=' + l + '&v=' + v + '&s=' + s + '&f=' + f + '&q=' + q; document.location.href = '/search?o=0&l=' + l + '&v=' + v + '&s=' + s + '&f=' + f + '&q=' + q;
} }
function mouseOver(id, view) { function mouseOver(id, view) {

View file

@ -15,6 +15,12 @@ def fix_ampersands(value):
''' '''
highlight search term in text, scipping html tags and script elements highlight search term in text, scipping html tags and script elements
''' '''
def insideTag(s):
return not (s.rfind('<') == -1 or s.rfind('>') > s.rfind('<'))
def insideScript(s):
return not (s.rfind('<script') == -1 or s.rfind('/script>') > s.rfind('<script'))
def highlightText(text, term): def highlightText(text, term):
highlightStart = u'<span class="textHighlight">' highlightStart = u'<span class="textHighlight">'
highlightEnd = u'</span>' highlightEnd = u'</span>'
@ -22,18 +28,20 @@ def highlightText(text, term):
if term.strip(): if term.strip():
term = term.lower() term = term.lower()
textLower = text.lower() textLower = text.lower()
fullTextLower = textLower
termLength = len(term) termLength = len(term)
fullPos = 0
while text: while text:
i = textLower.find(term) i = textLower.find(term)
if i == -1: if i == -1:
output += text output += text
break break
if textLower[:i].rfind('<') <= textLower[:i].rfind('>') and \ if not insideTag(fullTextLower[:fullPos+i]) and not insideScript(fullTextLower[:fullPos+i]):
textLower[:i].rfind('/script>') >= textLower[:i].rfind('<script'): output += text[:i] + highlightStart + text[i:i+termLength] + highlightEnd
output += text[:i] + highlightStart + text[i:i+termLength] + highlightEnd
else: else:
output += text[:i+termLength] output += text[:i+termLength]
text = text[i+termLength:] text = text[i+termLength:]
fullPos += i+termLength
textLower = text.lower() textLower = text.lower()
else: else:
output = text output = text