Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
9933d1bf
Commit
9933d1bf
authored
Jan 17, 2016
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce whoosh pressure by doing single query on every index
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
9986bab0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
18 deletions
+29
-18
weblate/trans/search.py
weblate/trans/search.py
+29
-18
No files found.
weblate/trans/search.py
View file @
9933d1bf
...
...
@@ -230,13 +230,20 @@ def update_index_unit(unit, source=True):
update_target_unit_index
(
writer
,
unit
)
def
base_search
(
searcher
,
field
,
schema
,
query
):
def
base_search
(
index
,
query
,
params
,
search
,
schema
):
'''
Wrapper for fulltext search.
'''
parser
=
qparser
.
QueryParser
(
field
,
schema
)
parsed
=
parser
.
parse
(
query
)
return
[
result
[
'pk'
]
for
result
in
searcher
.
search
(
parsed
)]
with
index
.
searcher
()
as
searcher
:
queries
=
[]
for
param
in
params
:
if
search
[
param
]:
parser
=
qparser
.
QueryParser
(
param
,
schema
)
queries
.
append
(
parser
.
parse
(
query
)
)
terms
=
reduce
(
lambda
x
,
y
:
x
|
y
,
queries
)
return
[
result
[
'pk'
]
for
result
in
searcher
.
search
(
terms
)]
def
fulltext_search
(
query
,
lang
,
params
):
...
...
@@ -255,21 +262,25 @@ def fulltext_search(query, lang, params):
search
.
update
(
params
)
if
search
[
'source'
]
or
search
[
'context'
]
or
search
[
'location'
]:
index
=
get_source_index
()
with
index
.
searcher
()
as
searcher
:
for
param
in
(
'source'
,
'context'
,
'location'
):
if
search
[
param
]:
pks
.
update
(
base_search
(
searcher
,
param
,
SourceSchema
(),
query
)
base_search
(
get_source_index
(),
query
,
(
'source'
,
'context'
,
'location'
),
search
,
SourceSchema
()
)
)
if
search
[
'target'
]
or
search
[
'comment'
]:
index
=
get_target_index
(
lang
)
with
index
.
searcher
()
as
searcher
:
for
param
in
(
'target'
,
'comment'
):
if
search
[
param
]:
pks
.
update
(
base_search
(
searcher
,
param
,
TargetSchema
(),
query
)
base_search
(
get_target_index
(
lang
),
query
,
(
'target'
,
'comment'
),
search
,
TargetSchema
()
)
)
return
pks
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment