Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
cc255e5f
Commit
cc255e5f
authored
6 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Handle NaN and inf floats in search query serializer
parent
801eeac0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/serializers/search.py
+17
-6
17 additions, 6 deletions
arkindex/documents/serializers/search.py
arkindex/documents/tests/test_search_api.py
+2
-0
2 additions, 0 deletions
arkindex/documents/tests/test_search_api.py
with
19 additions
and
6 deletions
arkindex/documents/serializers/search.py
+
17
−
6
View file @
cc255e5f
...
...
@@ -5,6 +5,7 @@ from arkindex.documents.serializers.elements import ElementLightSerializer
from
arkindex.documents.serializers.ml
import
TranscriptionSerializer
from
arkindex.project.serializer_fields
import
EnumField
,
SearchTermsField
from
arkindex.documents.date_parser
import
parse_date
import
math
class
SearchQuerySerializer
(
serializers
.
Serializer
):
...
...
@@ -27,15 +28,25 @@ class SearchQuerySerializer(serializers.Serializer):
raise
serializers
.
ValidationError
(
'
Could not parse Date
'
)
return
date
[
0
]
def
validate_score
(
self
,
value
):
if
not
isinstance
(
value
,
float
)
or
math
.
isinf
(
value
)
or
math
.
isnan
(
value
):
raise
serializers
.
ValidationError
(
'
Score should be a valid decimal number between 0 and 1
'
)
return
value
def
validate_date_gte
(
self
,
value
):
if
not
value
:
return
return
self
.
parse_date
(
value
).
es_str
()
def
validate_date_lte
(
self
,
value
):
if
not
value
:
return
return
self
.
parse_date
(
value
).
es_round_up
()
def
validate
(
self
,
data
):
data
=
super
().
validate
(
data
)
gte
=
data
[
'
date_gte
'
]
lt
=
data
[
'
date_lt
'
]
if
gte
:
gte
=
self
.
parse_date
(
gte
)
data
[
'
date_gte
'
]
=
gte
.
es_str
()
if
lt
:
lt
=
self
.
parse_date
(
lt
)
data
[
'
date_lt
'
]
=
lt
.
es_round_up
()
if
gte
and
lt
and
gte
>
lt
:
raise
serializers
.
ValidationError
(
"
Upper date must be greater than lower date
"
)
return
data
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/tests/test_search_api.py
+
2
−
0
View file @
cc255e5f
...
...
@@ -25,6 +25,8 @@ class TestSearchApi(FixtureAPITestCase):
{
'
q
'
:
'
'
,
'
score
'
:
'
0.7
'
},
{
'
q
'
:
'
one
'
,
'
score
'
:
'
1.01
'
},
{
'
q
'
:
'
that
'
,
'
score
'
:
'
null
'
},
{
'
q
'
:
'
that
'
,
'
score
'
:
'
nan
'
},
{
'
q
'
:
'
that
'
,
'
score
'
:
'
inf
'
},
{
'
q
'
:
'
one two
'
,
'
date_lte
'
:
'
1450-
'
},
{
'
q
'
:
'
one two
'
,
'
date_lte
'
:
'
1450-02-30
'
},
{
'
q
'
:
'
one
'
,
'
type
'
:
'
wrongtype
'
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment