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
3de2b13f
Commit
3de2b13f
authored
Jan 10, 2014
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Define Whoosh schemas as classes, it better fits with rest of the code
parent
99bbeff1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
16 deletions
+22
-16
weblate/trans/search.py
weblate/trans/search.py
+22
-16
No files found.
weblate/trans/search.py
View file @
3de2b13f
...
...
@@ -22,7 +22,7 @@
Whoosh based full text search.
'''
from
whoosh.fields
import
Schema
,
TEXT
,
ID
from
whoosh.fields
import
Schema
Class
,
TEXT
,
ID
from
whoosh.filedb.filestore
import
FileStorage
from
whoosh
import
qparser
from
django.db.models.signals
import
post_syncdb
...
...
@@ -31,18 +31,24 @@ from whoosh.writing import AsyncWriter, BufferedWriter
from
django.dispatch
import
receiver
from
weblate.lang.models
import
Language
TARGET_SCHEMA
=
Schema
(
checksum
=
ID
(
stored
=
True
,
unique
=
True
),
target
=
TEXT
)
STORAGE
=
FileStorage
(
appsettings
.
WHOOSH_INDEX
)
SOURCE_SCHEMA
=
Schema
(
checksum
=
ID
(
stored
=
True
,
unique
=
True
),
source
=
TEXT
,
context
=
TEXT
)
STORAGE
=
FileStorage
(
appsettings
.
WHOOSH_INDEX
)
class
TargetSchema
(
SchemaClass
):
'''
Fultext index schema for target strings.
'''
checksum
=
ID
(
stored
=
True
,
unique
=
True
)
target
=
TEXT
()
class
SourceSchema
(
SchemaClass
):
'''
Fultext index schema for source and context strings.
'''
checksum
=
ID
(
stored
=
True
,
unique
=
True
)
source
=
TEXT
()
context
=
TEXT
()
@
receiver
(
post_syncdb
)
...
...
@@ -57,14 +63,14 @@ def create_source_index():
'''
Creates source string index.
'''
return
STORAGE
.
create_index
(
S
OURCE_SCHEMA
,
'source'
)
return
STORAGE
.
create_index
(
S
ourceSchema
,
'source'
)
def
create_target_index
(
lang
):
'''
Creates traget string index for given language.
'''
return
STORAGE
.
create_index
(
T
ARGET_SCHEMA
,
'target-%s'
%
lang
)
return
STORAGE
.
create_index
(
T
argetSchema
,
'target-%s'
%
lang
)
def
update_source_unit_index
(
writer
,
unit
):
...
...
@@ -186,18 +192,18 @@ def fulltext_search(query, lang, source=True, context=True, target=True):
with
index
.
searcher
()
as
searcher
:
if
source
:
checksums
.
update
(
base_search
(
searcher
,
'source'
,
S
OURCE_SCHEMA
,
query
)
base_search
(
searcher
,
'source'
,
S
ourceSchema
,
query
)
)
if
context
:
checksums
.
update
(
base_search
(
searcher
,
'context'
,
S
OURCE_SCHEMA
,
query
)
base_search
(
searcher
,
'context'
,
S
ourceSchema
,
query
)
)
if
target
:
index
=
get_target_index
(
lang
)
with
index
.
searcher
()
as
searcher
:
checksums
.
update
(
base_search
(
searcher
,
'target'
,
T
ARGET_SCHEMA
,
query
)
base_search
(
searcher
,
'target'
,
T
argetSchema
,
query
)
)
return
checksums
...
...
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