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
9c8b8a4e
Commit
9c8b8a4e
authored
Apr 03, 2012
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor our fulltext searching
parent
e0826295
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
10 deletions
+13
-10
trans/managers.py
trans/managers.py
+13
-10
No files found.
trans/managers.py
View file @
9c8b8a4e
...
...
@@ -183,25 +183,28 @@ class UnitManager(models.Manager):
unit
.
translation_id
,
writer_target
)
def
__search
(
self
,
searcher
,
field
,
schema
,
query
):
'''
Wrapper for fulltext search.
'''
qp
=
qparser
.
QueryParser
(
field
,
schema
)
q
=
qp
.
parse
(
query
)
return
[
searcher
.
stored_fields
(
d
)[
'checksum'
]
for
d
in
searcher
.
docs_for_query
(
q
)]
def
search
(
self
,
query
,
source
=
True
,
context
=
True
,
translation
=
True
,
checksums
=
False
):
ret
=
set
()
sample
=
self
.
all
()[
0
]
if
source
or
context
:
with
trans
.
search
.
get_source_searcher
()
as
searcher
:
if
source
:
qp
=
qparser
.
QueryParser
(
'source'
,
trans
.
search
.
SourceSchema
())
q
=
qp
.
parse
(
query
)
ret
=
ret
.
union
([
searcher
.
stored_fields
(
d
)[
'checksum'
]
for
d
in
searcher
.
docs_for_query
(
q
)])
ret
=
ret
.
union
(
self
.
__search
(
searcher
,
'source'
,
trans
.
search
.
SourceSchema
(),
query
))
if
context
:
qp
=
qparser
.
QueryParser
(
'context'
,
trans
.
search
.
SourceSchema
())
q
=
qp
.
parse
(
query
)
ret
=
ret
.
union
([
searcher
.
stored_fields
(
d
)[
'checksum'
]
for
d
in
searcher
.
docs_for_query
(
q
)])
ret
=
ret
.
union
(
self
.
__search
(
searcher
,
'context'
,
trans
.
search
.
SourceSchema
(),
query
))
if
translation
:
sample
=
self
.
all
()[
0
]
with
trans
.
search
.
get_target_searcher
(
sample
.
translation
.
language
.
code
)
as
searcher
:
qp
=
qparser
.
QueryParser
(
'target'
,
trans
.
search
.
TargetSchema
())
q
=
qp
.
parse
(
query
)
ret
=
ret
.
union
([
searcher
.
stored_fields
(
d
)[
'checksum'
]
for
d
in
searcher
.
docs_for_query
(
q
)])
ret
=
ret
.
union
(
self
.
__search
(
searcher
,
'target'
,
trans
.
search
.
TargetSchema
(),
query
))
if
checksums
:
return
ret
...
...
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