Skip to content

Commit 4a44ef3

Browse files
committed
Updated whoosh to 2.5.3
1 parent aaf1c57 commit 4a44ef3

File tree

127 files changed

+30722
-15957
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+30722
-15957
lines changed

ldoce5viewer/fulltext.py

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'''Full-text searcher for headwords/phrases/examples/definitions
22
3-
It is powered by the Whoosh FTS library.
3+
powered by the Whoosh FTS library
44
'''
55

66
from __future__ import absolute_import
@@ -14,10 +14,11 @@
1414
from .whoosh.fields import Schema, STORED, IDLIST, ID, TEXT
1515
from .whoosh.analysis import StandardAnalyzer, Filter
1616
from .whoosh.query import Variations, Term, Or, And
17-
from .whoosh.qparser import QueryParser,\
17+
from .whoosh.qparser import QueryParser, \
1818
RangePlugin, BoostPlugin, WildcardPlugin, OperatorsPlugin
1919
from .whoosh.highlight import WholeFragmenter, HtmlFormatter
20-
from .whoosh.searching import Collector, Aborted
20+
from .whoosh.collectors import WrappingCollector, \
21+
UnlimitedCollector, TopCollector
2122

2223
from .utils.cdb import CDBReader, CDBMaker, CDBError
2324
from .utils.text import normalize_token, normalize_index_key,\
@@ -28,6 +29,26 @@ class IndexError(Exception):
2829
pass
2930

3031

32+
class AbortableCollector(WrappingCollector):
33+
def __init__(self, child):
34+
WrappingCollector.__init__(self, child)
35+
self._aborted = False
36+
37+
def collect_matches(self):
38+
collect = self.collect
39+
for sub_docnum in self.matches():
40+
if self._aborted:
41+
break
42+
collect(sub_docnum)
43+
44+
@property
45+
def aborted(self):
46+
return self._aborted
47+
48+
def abort(self):
49+
self._aborted = True
50+
51+
3152
#-----------------
3253
# Word Vatiations
3354
#-----------------
@@ -228,16 +249,19 @@ def _make_var_reader(self, var_path):
228249
except (EnvironmentError, CDBError):
229250
return None
230251

231-
def make_collector(self, limit):
232-
return Collector(limit=limit)
233-
234252
def correct(self, misspelled, limit=5):
235253
with self._index.searcher() as searcher:
236254
corrector = searcher.corrector("content")
237255
return corrector.suggest(misspelled, limit)
238256

239-
def search(self, query_str1=None, query_str2=None, itemtypes=(),
240-
limit=1000, highlight=False, collector=None):
257+
def make_collector(self, limit=None):
258+
if limit is None:
259+
return AbortableCollector(UnlimitedCollector())
260+
else:
261+
return AbortableCollector(TopCollector(limit))
262+
263+
def search(self, collector, query_str1=None, query_str2=None,
264+
itemtypes=(), highlight=False):
241265

242266
# rejects '*' and '?'
243267
if query_str1:
@@ -269,11 +293,8 @@ def search(self, query_str1=None, query_str2=None, itemtypes=(),
269293

270294
query = And(andlist)
271295

272-
# Search
273-
if collector:
274-
hits = collector.search(searcher, query)
275-
else:
276-
hits = searcher.search(query, limit=limit)
296+
searcher.search_with_collector(query, collector)
297+
hits = collector.results()
277298

278299
if highlight:
279300
hits.fragmenter = WholeFragmenter()
@@ -287,8 +308,8 @@ def search(self, query_str1=None, query_str2=None, itemtypes=(),
287308
# Construct a result list
288309
results = []
289310
for hit in hits:
290-
if collector and collector._aborted:
291-
raise Aborted
311+
if collector.aborted:
312+
return []
292313
(label, path, prio, sortkey) = hit['data']
293314

294315
if wildcard and query_str1:
@@ -310,3 +331,4 @@ def search(self, query_str1=None, query_str2=None, itemtypes=(),
310331

311332
# Return
312333
return results
334+

ldoce5viewer/qtgui/advanced.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,9 @@ def setFocusOnPhraseBox(self):
176176
<html lang="en">
177177
<head>
178178
<meta charset="utf-8">
179-
<link rel="stylesheet" type="text/css" href="static:///styles/search.css">
180-
<script src="static:///scripts/jquery.js"
181-
type="application/javascript"></script>
182-
<script src="static:///scripts/search.js"
183-
type="application/javascript"></script>'
179+
<link rel="stylesheet" href="static:///styles/search.css">
180+
<script src="static:///scripts/jquery.js"></script>
181+
<script src="static:///scripts/search.js"></script>
184182
</head>
185183
<body>"""
186184

@@ -287,10 +285,11 @@ def search_and_render(url, fulltext_hp, fulltext_de):
287285
if mode in MODE_DICT:
288286
spec = MODE_DICT[mode]
289287
searcher = fulltext_hp if (spec['searcher'] == 'hp') else fulltext_de
288+
collector = searcher.make_collector(spec['limit'])
290289
res = searcher.search(
290+
collector,
291291
query_str1=phrase, query_str2=filters,
292292
itemtypes=spec['itemtypes'],
293-
limit=spec['limit'],
294293
highlight=spec['highlight'])
295294
r.append(_render_header(spec['title'], mode, phrase, filters))
296295
r.append(spec['renderer'](res, mode))

ldoce5viewer/qtgui/async.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Asynchlonous full-text search facility for headwords and phrases"""
1+
"""Asynchlonous full-text search facility for phrase search"""
22

33
from __future__ import absolute_import
44
from __future__ import unicode_literals
@@ -8,8 +8,6 @@
88
from PyQt4.QtCore import (
99
QObject, QThread, QMutex, QWaitCondition, pyqtSignal)
1010

11-
from ..whoosh.searching import Aborted
12-
1311
_logger = logging.getLogger(__name__)
1412

1513

@@ -50,21 +48,22 @@ def run(self):
5048

5149
try:
5250
result = self._searcher.search(
51+
collector,
5352
query_str1, query_str2,
54-
itemtypes, limit, highlight, collector)
55-
except Aborted:
56-
pass
53+
itemtypes, highlight)
5754
except:
58-
raise
5955
self._mutex.lock()
6056
self._result = None
6157
self._mutex.unlock()
6258
self.searchError.emit()
6359
else:
64-
self._mutex.lock()
65-
self._result = (merge, result)
66-
self._mutex.unlock()
67-
self.searchFinished.emit()
60+
if collector.aborted:
61+
pass
62+
else:
63+
self._mutex.lock()
64+
self._result = (merge, result)
65+
self._mutex.unlock()
66+
self.searchFinished.emit()
6867

6968
self._mutex.lock()
7069
self._collector = None

ldoce5viewer/whoosh/LICENSE.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

ldoce5viewer/whoosh/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
# those of the authors and should not be interpreted as representing official
2626
# policies, either expressed or implied, of Matt Chaput.
2727

28-
__version__ = (2, 3, 2)
28+
__version__ = (2, 5, 3)
2929

3030

3131
def versionstring(build=True, extra=True):
3232
"""Returns the version number of Whoosh as a string.
33-
33+
3434
:param build: Whether to include the build number in the string.
3535
:param extra: Whether to include alpha/beta/rc etc. tags. Only
3636
checked if build is True.

0 commit comments

Comments
 (0)