jump to first page for new searches, or if o not in range, fix highlightText
This commit is contained in:
parent
36dfdcaa50
commit
5c247d77ed
4 changed files with 18 additions and 5 deletions
|
@ -259,6 +259,8 @@ class Root(controllers.RootController):
|
|||
if v == 'quote':
|
||||
tg_template = ".templates.quoteview"
|
||||
|
||||
if f != 'all' and s == 'relevance':
|
||||
s='title'
|
||||
orderBy = [self.get_sort(s), 'title_sort', 'rel_date']
|
||||
if q:
|
||||
q = q.encode('utf-8')
|
||||
|
@ -273,11 +275,13 @@ class Root(controllers.RootController):
|
|||
sort = sort[1:]
|
||||
sort = self._search_map.get(sort, sort)
|
||||
sort = self._sort_map.get(sort, sort)
|
||||
print sort
|
||||
if type(items) == list:
|
||||
search['length'] = len(items)
|
||||
else:
|
||||
search['length'] = items.count()
|
||||
if o > search['length']:
|
||||
o = 0
|
||||
search['o'] = 0
|
||||
cherrypy.session['search'] = search
|
||||
return dict(items = items[o:o+n], sort = sort, search = search, tg_template = tg_template)
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ class ArchiveItem(SQLObject):
|
|||
ALTER TABLE archive_item ADD FULLTEXT (title, description, text);
|
||||
ALTER TABLE archive_item CHANGE size size bigint;
|
||||
ALTER TABLE archive_item CHANGE html html longtext;
|
||||
ALTER TABLE archive_item CHANGE description description longtext;
|
||||
ALTER TABLE archive_item CHANGE text text longtext;
|
||||
'''
|
||||
hashId = UnicodeCol(alternateID = True, length=128)
|
||||
|
|
|
@ -20,7 +20,7 @@ function submitFind() {
|
|||
var s = document.getElementById('selectSort').value;
|
||||
var f = document.getElementById('selectFind').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) {
|
||||
|
|
|
@ -15,6 +15,12 @@ def fix_ampersands(value):
|
|||
'''
|
||||
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):
|
||||
highlightStart = u'<span class="textHighlight">'
|
||||
highlightEnd = u'</span>'
|
||||
|
@ -22,18 +28,20 @@ def highlightText(text, term):
|
|||
if term.strip():
|
||||
term = term.lower()
|
||||
textLower = text.lower()
|
||||
fullTextLower = textLower
|
||||
termLength = len(term)
|
||||
fullPos = 0
|
||||
while text:
|
||||
i = textLower.find(term)
|
||||
if i == -1:
|
||||
output += text
|
||||
break
|
||||
if textLower[:i].rfind('<') <= textLower[:i].rfind('>') and \
|
||||
textLower[:i].rfind('/script>') >= textLower[:i].rfind('<script'):
|
||||
if not insideTag(fullTextLower[:fullPos+i]) and not insideScript(fullTextLower[:fullPos+i]):
|
||||
output += text[:i] + highlightStart + text[i:i+termLength] + highlightEnd
|
||||
else:
|
||||
output += text[:i+termLength]
|
||||
text = text[i+termLength:]
|
||||
fullPos += i+termLength
|
||||
textLower = text.lower()
|
||||
else:
|
||||
output = text
|
||||
|
|
Loading…
Reference in a new issue