annotate MoinMoin/search/results.py @ 6101:316986758258

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