1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854
|
# -*- coding: iso-8859-1 -*-
"""
MoinMoin - search results processing
@copyright: 2005 MoinMoin:FlorianFesti,
2005 MoinMoin:NirSoffer,
2005 MoinMoin:AlexanderSchremmer,
2006 MoinMoin:ThomasWaldmann,
2006 MoinMoin:FranzPletz
@license: GNU GPL, see COPYING for details
"""
import StringIO, time
from MoinMoin import wikiutil
from MoinMoin.Page import Page
############################################################################
### Results
############################################################################
class Match(object):
""" Base class for all Matches (found pieces of pages).
This class represents a empty True value as returned from negated searches.
"""
# Default match weight
_weight = 1.0
def __init__(self, start=0, end=0, re_match=None):
self.re_match = re_match
if not re_match:
self._start = start
self._end = end
else:
self._start = self._end = 0
def __len__(self):
return self.end - self.start
def __eq__(self, other):
equal = (self.__class__ == other.__class__ and
self.start == other.start and
self.end == other.end)
return equal
def __ne__(self, other):
return not self.__eq__(other)
def view(self):
return ''
def weight(self):
return self._weight
def _get_start(self):
if self.re_match:
return self.re_match.start()
return self._start
def _get_end(self):
if self.re_match:
return self.re_match.end()
return self._end
# object properties
start = property(_get_start)
end = property(_get_end)
class TextMatch(Match):
""" Represents a match in the page content """
pass
class TitleMatch(Match):
""" Represents a match in the page title
Has more weight than a match in the page content.
"""
# Matches in titles are much more important in wikis. This setting
# seems to make all pages that have matches in the title to appear
# before pages that their title does not match.
_weight = 100.0
class AttachmentMatch(Match):
""" Represents a match in a attachment content
Not used yet.
"""
pass
class FoundPage(object):
""" Represents a page in a search result """
def __init__(self, page_name, matches=None, page=None, rev=0):
self.page_name = page_name
self.attachment = '' # this is not an attachment
self.page = page
self.rev = rev
if matches is None:
matches = []
self._matches = matches
def weight(self, unique=1):
""" returns how important this page is for the terms searched for
Summarize the weight of all page matches
@param unique: ignore identical matches
@rtype: int
@return: page weight
"""
weight = 0
for match in self.get_matches(unique=unique):
weight += match.weight()
# More sophisticated things to be added, like increase
# weight of near matches.
if self.page.parse_processing_instructions().get('deprecated', False):
weight = int(weight / 4) # rank it down
return weight
def add_matches(self, matches):
""" Add found matches """
self._matches.extend(matches)
def get_matches(self, unique=1, sort='start', type=Match):
""" Return all matches of type sorted by sort
@param unique: return only unique matches (bool)
@param sort: match attribute to sort by (string)
@param type: type of match to return (Match or sub class)
@rtype: list
@return: list of matches
"""
if unique:
matches = self._unique_matches(type=type)
if sort == 'start':
# matches already sorted by match.start, finished.
return matches
else:
matches = self._matches
# Filter by type and sort by sort using fast schwartzian transform.
if sort == 'start':
tmp = [(match.start, match) for match in matches if isinstance(match, type)]
else:
tmp = [(match.weight(), match) for match in matches if isinstance(match, type)]
tmp.sort()
if sort == 'weight':
tmp.reverse()
matches = [item[1] for item in tmp]
return matches
def _unique_matches(self, type=Match):
""" Get a list of unique matches of type
The result is sorted by match.start, because its easy to remove
duplicates like this.
@param type: type of match to return
@rtype: list
@return: list of matches of type, sorted by match.start
"""
# Filter by type and sort by match.start using fast schwartzian transform.
tmp = [(match.start, match) for match in self._matches if isinstance(match, type)]
tmp.sort()
if not len(tmp):
return []
# Get first match into matches list
matches = [tmp[0][1]]
# Add the remaining ones of matches ignoring identical matches
for item in tmp[1:]:
if item[1] == matches[-1]:
continue
matches.append(item[1])
return matches
class FoundAttachment(FoundPage):
""" Represents an attachment in search results """
def __init__(self, page_name, attachment, matches=None, page=None, rev=0):
self.page_name = page_name
self.attachment = attachment
self.rev = rev
self.page = page
if matches is None:
matches = []
self._matches = matches
def weight(self, unique=1):
return 1
class FoundRemote(FoundPage):
""" Represents a remote search result """
def __init__(self, wikiname, page_name, attachment, matches=None, page=None, rev=0):
self.wikiname = wikiname
self.page_name = page_name
self.rev = rev
self.attachment = attachment
self.page = page
if matches is None:
matches = []
self._matches = matches
def weight(self, unique=1):
return 1
def get_matches(self, unique=1, sort='start', type=Match):
return []
def _unique_matches(self, type=Match):
return []
############################################################################
### Search results formatting
############################################################################
class SearchResults(object):
""" Manage search results, supply different views
Search results can hold valid search results and format them for
many requests, until the wiki content changes.
For example, one might ask for full page list sorted from A to Z,
and then ask for the same list sorted from Z to A. Or sort results
by name and then by rank.
"""
# Public functions --------------------------------------------------
def __init__(self, query, hits, pages, elapsed, sort, estimated_hits):
self.query = query # the query
self.hits = hits # hits list
self.pages = pages # number of pages in the wiki
self.elapsed = elapsed # search time
self.estimated_hits = estimated_hits # about how much hits?
if sort == 'weight':
self._sortByWeight()
elif sort == 'page_name':
self._sortByPagename()
self.sort = sort
def _sortByWeight(self):
""" Sorts found pages by the weight of the matches """
tmp = [(hit.weight(), hit.page_name, hit.attachment, hit) for hit in self.hits]
tmp.sort()
tmp.reverse()
self.hits = [item[3] for item in tmp]
def _sortByPagename(self):
""" Sorts a list of found pages alphabetical by page/attachment name """
tmp = [(hit.page_name, hit.attachment, hit) for hit in self.hits]
tmp.sort()
self.hits = [item[2] for item in tmp]
def stats(self, request, formatter, hitsFrom):
""" Return search statistics, formatted with formatter
@param request: current request
@param formatter: formatter to use
@param hitsFrom: current position in the hits
@rtype: unicode
@return formatted statistics
"""
_ = request.getText
if not self.estimated_hits:
self.estimated_hits = ('', len(self.hits))
output = [
formatter.paragraph(1, attr={'class': 'searchstats'}),
_("Results %(bs)s%(hitsFrom)d - %(hitsTo)d%(be)s "
"of %(aboutHits)s %(bs)s%(hits)d%(be)s results out of "
"about %(pages)d pages.") %
{'aboutHits': self.estimated_hits[0],
'hits': self.estimated_hits[1], 'pages': self.pages,
'hitsFrom': hitsFrom + 1,
'hitsTo': hitsFrom +
min(self.estimated_hits[1] - hitsFrom,
request.cfg.search_results_per_page),
'bs': formatter.strong(1), 'be': formatter.strong(0)},
u' (%s %s)' % (''.join([formatter.strong(1),
formatter.text("%.2f" % self.elapsed),
formatter.strong(0)]),
formatter.text(_("seconds"))),
formatter.paragraph(0),
]
return ''.join(output)
def pageList(self, request, formatter, info=0, numbered=1,
paging=True, hitsFrom=0, hitsInfo=0, highlight_titles=True,
highlight_pages=True):
""" Format a list of found pages
@param request: current request
@param formatter: formatter to use
@param info: show match info in title
@param numbered: use numbered list for display
@param paging: toggle paging
@param hitsFrom: current position in the hits
@param hitsInfo: toggle hits info line
@param highlight_titles: performa highlighting in page list
@param highlight_pages: add highlight parameter to page link URLs in
search results
@rtype: unicode
@return formatted page list
"""
self._reset(request, formatter)
f = formatter
write = self.buffer.write
if numbered:
lst = lambda on: f.number_list(on, start=hitsFrom+1)
else:
lst = f.bullet_list
if paging and len(self.hits) <= request.cfg.search_results_per_page:
paging = False
# Add pages formatted as list
if self.hits:
write(lst(1))
if paging:
hitsTo = hitsFrom + request.cfg.search_results_per_page
displayHits = self.hits[hitsFrom:hitsTo]
else:
displayHits = self.hits
for page in displayHits:
if isinstance(page, FoundRemote):
# TODO handle FoundRemote (interwiki) search hits
continue
elif isinstance(page, FoundAttachment):
querydict = {
'action': 'AttachFile',
'do': 'view',
'target': page.attachment,
}
elif isinstance(page, FoundPage):
if page.rev and page.rev != page.page.getRevList()[0]:
querydict = {
'rev': page.rev,
}
else:
querydict = None
querystr = self.querystring(querydict, do_highlight=highlight_pages)
matchInfo = ''
if info:
matchInfo = self.formatInfo(f, page)
info_for_hits = u''
if hitsInfo:
info_for_hits = self.formatHitInfoBar(page)
item = [
f.listitem(1),
f.pagelink(1, page.page_name, querystr=querystr),
self.formatTitle(page, highlight_titles=highlight_titles),
f.pagelink(0, page.page_name),
matchInfo,
info_for_hits,
f.listitem(0),
]
write(''.join(item))
write(lst(0))
if paging:
write(self.formatPageLinks(hitsFrom=hitsFrom,
hitsPerPage=request.cfg.search_results_per_page,
hitsNum=len(self.hits)))
return self.getvalue()
def pageListWithContext(self, request, formatter, info=1, context=180,
maxlines=1, paging=True, hitsFrom=0, hitsInfo=0,
highlight_titles=True, highlight_pages=True):
""" Format a list of found pages with context
@param request: current request
@param formatter: formatter to use
@param info: show match info near the page link
@param context: how many characters to show around each match.
@param maxlines: how many contexts lines to show.
@param paging: toggle paging
@param hitsFrom: current position in the hits
@param hitsInfo: toggle hits info line
@param highlight_titles: perform highlighting in page list
@param highlight_pages: add highlight parameter to page URLs
@rtype: unicode
@return formatted page list with context
"""
self._reset(request, formatter)
f = formatter
write = self.buffer.write
_ = request.getText
if paging and len(self.hits) <= request.cfg.search_results_per_page:
paging = False
# Add pages formatted as definition list
if self.hits:
write(f.definition_list(1))
if paging:
hitsTo = hitsFrom + request.cfg.search_results_per_page
displayHits = self.hits[hitsFrom:hitsTo]
else:
displayHits = self.hits
for page in displayHits:
# TODO handle interwiki search hits
matchInfo = ''
if info:
matchInfo = self.formatInfo(f, page)
if page.attachment:
fmt_context = ""
querydict = {
'action': 'AttachFile',
'do': 'view',
'target': page.attachment,
}
elif page.page_name.startswith('FS/'): # XXX FS hardcoded
fmt_context = ""
querydict = None
else:
fmt_context = self.formatContext(page, context, maxlines)
if page.rev and page.rev != page.page.getRevList()[0]:
querydict = {
'rev': page.rev,
}
else:
querydict = None
querystr = self.querystring(querydict,
do_highlight=highlight_pages)
item = [
f.definition_term(1),
f.pagelink(1, page.page_name, querystr=querystr),
self.formatTitle(page, highlight_titles=highlight_titles),
f.pagelink(0, page.page_name),
matchInfo,
f.definition_term(0),
f.definition_desc(1),
fmt_context,
f.definition_desc(0),
self.formatHitInfoBar(page),
]
write(''.join(item))
write(f.definition_list(0))
if paging:
write(self.formatPageLinks(hitsFrom=hitsFrom,
hitsPerPage=request.cfg.search_results_per_page,
hitsNum=len(self.hits)))
return self.getvalue()
# Private -----------------------------------------------------------
# This methods are not meant to be used by clients and may change
# without notice.
def formatContext(self, page, context, maxlines):
""" Format search context for each matched page
Try to show first maxlines interesting matches context.
"""
f = self.formatter
if not page.page:
page.page = Page(self.request, page.page_name)
body = page.page.get_raw_body()
last = len(body) - 1
lineCount = 0
output = []
# Get unique text matches sorted by match.start, try to ignore
# matches in page header, and show the first maxlines matches.
# TODO: when we implement weight algorithm for text matches, we
# should get the list of text matches sorted by weight and show
# the first maxlines matches.
matches = page.get_matches(unique=1, sort='start', type=TextMatch)
i, start = self.firstInterestingMatch(page, matches)
# Format context
while i < len(matches) and lineCount < maxlines:
match = matches[i]
# Get context range for this match
start, end = self.contextRange(context, match, start, last)
# Format context lines for matches. Each complete match in
# the context will be highlighted, and if the full match is
# in the context, we increase the index, and will not show
# same match again on a separate line.
output.append(f.text(u'...'))
# Get the index of the first match completely within the
# context.
for j in xrange(0, len(matches)):
if matches[j].start >= start:
break
# Add all matches in context and the text between them
while True:
match = matches[j]
# Ignore matches behind the current position
if start < match.end:
# Append the text before match
if start < match.start:
output.append(f.text(body[start:match.start]))
# And the match
output.append(self.formatMatch(body, match, start))
start = match.end
# Get next match, but only if its completely within the context
if j < len(matches) - 1 and matches[j + 1].end <= end:
j += 1
else:
break
# Add text after last match and finish the line
if match.end < end:
output.append(f.text(body[match.end:end]))
output.append(f.text(u'...'))
output.append(f.linebreak(preformatted=0))
# Increase line and point to the next match
lineCount += 1
i = j + 1
output = ''.join(output)
if not output:
# Return the first context characters from the page text
output = f.text(page.page.getPageText(length=context))
output = output.strip()
if not output:
# This is a page with no text, only header, for example,
# a redirect page.
output = f.text(page.page.getPageHeader(length=context))
return output
def firstInterestingMatch(self, page, matches):
""" Return the first interesting match
This function is needed only because we don't have yet a weight
algorithm for page text matches.
Try to find the first match in the page text. If we can't find
one, we return the first match and start=0.
@rtype: tuple
@return: index of first match, start of text
"""
header = page.page.getPageHeader()
start = len(header)
# Find first match after start
for i in xrange(len(matches)):
if matches[i].start >= start and \
isinstance(matches[i], TextMatch):
return i, start
return 0, 0
def contextRange(self, context, match, start, last):
""" Compute context range
Add context around each match. If there is no room for context
before or after the match, show more context on the other side.
@param context: context length
@param match: current match
@param start: context should not start before that index, unless
end is past the last character.
@param last: last character index
@rtype: tuple
@return: start, end of context
"""
# Start by giving equal context on both sides of match
contextlen = max(context - len(match), 0)
cstart = match.start - contextlen / 2
cend = match.end + contextlen / 2
# If context start before start, give more context on end
if cstart < start:
cend += start - cstart
cstart = start
# But if end if after last, give back context to start
if cend > last:
cstart -= cend - last
cend = last
# Keep context start positive for very short texts
cstart = max(cstart, 0)
return cstart, cend
def formatTitle(self, page, highlight_titles=True):
""" Format page title
Invoke format match on all unique matches in page title.
@param page: found page
@param highlight_titles: highlight search query matches
@rtype: unicode
@return: formatted title
"""
if highlight_titles:
# Get unique title matches sorted by match.start
matches = page.get_matches(unique=1, sort='start', type=TitleMatch)
else:
matches = []
# Format
pagename = page.page_name
f = self.formatter
output = []
start = 0
for match in matches:
# Ignore matches behind the current position
if start < match.end:
# Append the text before the match
if start < match.start:
output.append(f.text(pagename[start:match.start]))
# And the match
output.append(self.formatMatch(pagename, match, start))
start = match.end
# Add text after match
if start < len(pagename):
output.append(f.text(pagename[start:]))
if page.attachment: # show the attachment that matched
output.extend([
" ",
f.strong(1),
f.text("(%s)" % page.attachment),
f.strong(0)])
return ''.join(output)
def formatMatch(self, body, match, location):
""" Format single match in text
Format the part of the match after the current location in the
text. Matches behind location are ignored and an empty string is
returned.
@param body: text containing match
@param match: search match in text
@param location: current location in text
@rtype: unicode
@return: formatted match or empty string
"""
start = max(location, match.start)
if start < match.end:
f = self.formatter
output = [
f.strong(1),
f.text(body[start:match.end]),
f.strong(0),
]
return ''.join(output)
return ''
def formatPageLinks(self, hitsFrom, hitsPerPage, hitsNum):
""" Format previous and next page links in page
@param hitsFrom: current position in the hits
@param hitsPerPage: number of hits per page
@param hitsNum: number of hits
@rtype: unicode
@return: links to previous and next pages (if exist)
"""
_ = self.request.getText
f = self.formatter
querydict = wikiutil.parseQueryString(self.request.query_string).to_dict()
def page_url(n):
querydict.update({'from': n * hitsPerPage})
return self.request.page.url(self.request, querydict, escape=0)
pages = hitsNum // hitsPerPage
remainder = hitsNum % hitsPerPage
if remainder:
pages += 1
cur_page = hitsFrom // hitsPerPage
textlinks = []
# previous page available
if cur_page > 0:
textlinks.append(''.join([
f.url(1, href=page_url(cur_page-1)),
f.text(_('Previous')),
f.url(0)]))
else:
textlinks.append('')
# list of pages to be shown
page_range = range(*(
cur_page - 5 < 0 and
(0, pages > 10 and 10 or pages) or
(cur_page - 5, cur_page + 6 > pages and
pages or cur_page + 6)))
textlinks.extend([''.join([
i != cur_page and f.url(1, href=page_url(i)) or '',
f.text(str(i+1)),
i != cur_page and f.url(0) or '',
]) for i in page_range])
# next page available
if cur_page < pages - 1:
textlinks.append(''.join([
f.url(1, href=page_url(cur_page+1)),
f.text(_('Next')),
f.url(0)]))
else:
textlinks.append('')
return ''.join([
f.table(1, attrs={'tableclass': 'searchpages'}),
f.table_row(1),
f.table_cell(1),
# textlinks
(f.table_cell(0) + f.table_cell(1)).join(textlinks),
f.table_cell(0),
f.table_row(0),
f.table(0),
])
def formatHitInfoBar(self, page):
""" Returns the code for the information below a search hit
@param page: the FoundPage instance
"""
request = self.request
f = self.formatter
_ = request.getText
p = page.page
rev = p.get_real_rev()
if rev is None:
rev = 0
size_str = '%.1fk' % (p.size()/1024.0)
revisions = p.getRevList()
if len(revisions) and rev == revisions[0]:
rev_str = '%s: %d (%s)' % (_('rev'), rev, _('current'))
else:
rev_str = '%s: %d' % (_('rev'), rev, )
lastmod_str = _('last modified: %s') % p.mtime_printable(request)
result = f.paragraph(1, attr={'class': 'searchhitinfobar'}) + \
f.text('%s - %s %s' % (size_str, rev_str, lastmod_str)) + \
f.paragraph(0)
return result
def querystring(self, querydict=None, do_highlight=True):
""" Return query string, used in the page link
@keyword querydict: use these parameters (default: None)
@keyword do_highlight: add highlight parameter to URL (default: yes)
"""
if querydict is None:
querydict = {}
if do_highlight and ('action' not in querydict or
querydict['action'] == 'AttachFile'):
highlight = self.query.highlight_re()
if highlight:
querydict.update({'highlight': highlight})
querystr = wikiutil.makeQueryString(querydict)
return querystr
def formatInfo(self, formatter, page):
""" Return formatted match info
@param formatter: the formatter instance to use
@param page: the current page instance
"""
template = u' . . . %s %s'
template = u"%s%s%s" % (formatter.span(1, css_class="info"),
template,
formatter.span(0))
# Count number of unique matches in text of all types
count = len(page.get_matches(unique=1))
info = template % (count, self.matchLabel[count != 1])
return info
def getvalue(self):
""" Return output in div with CSS class """
value = [
self.formatter.div(1, css_class='searchresults'),
self.buffer.getvalue(),
self.formatter.div(0),
]
return '\n'.join(value)
def _reset(self, request, formatter):
""" Update internal state before new output
Do not call this, it should be called only by the instance code.
Each request might need different translations or other user preferences.
@param request: current request
@param formatter: the formatter instance to use
"""
self.buffer = StringIO.StringIO()
self.formatter = formatter
self.request = request
# Use 1 match, 2 matches...
_ = request.getText
self.matchLabel = (_('match'), _('matches'))
def getSearchResults(request, query, hits, start, sort, estimated_hits):
""" Return a SearchResults object with the specified properties
@param request: current request
@param query: the search query object tree
@param hits: list of hits
@param start: position to start showing the hits
@param sort: sorting of the results, either 'weight' or 'page_name'
@param estimated_hits: if true, use this estimated hit count
"""
result_hits = []
for wikiname, page, attachment, match, rev in hits:
if wikiname in (request.cfg.interwikiname, 'Self'): # a local match
if attachment:
result_hits.append(FoundAttachment(page.page_name, attachment, matches=match, page=page, rev=rev))
else:
result_hits.append(FoundPage(page.page_name, matches=match, page=page, rev=rev))
else:
page_name = page # for remote wikis, we have the page_name, not the page obj
result_hits.append(FoundRemote(wikiname, page_name, attachment, matches=match, rev=rev))
elapsed = time.time() - start
count = request.rootpage.getPageCount()
return SearchResults(query, result_hits, count, elapsed, sort,
estimated_hits)
|