Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
elasticsearch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
la forge Heptapod sera en maintenance de 12h à 13h le mardi 18 mars 2025
Show more breadcrumbs
cubicweb
cubes
elasticsearch
Commits
51da60b64969
Commit
51da60b64969
authored
8 years ago
by
Adrien Di Mascio
Browse files
Options
Downloads
Patches
Plain Diff
[tests] fix parent tests
parent
b0b8d7027869
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
search_helpers.py
+2
-1
2 additions, 1 deletion
search_helpers.py
test/test_parents.py
+47
-36
47 additions, 36 deletions
test/test_parents.py
with
49 additions
and
37 deletions
search_helpers.py
+
2
−
1
View file @
51da60b6
...
...
@@ -61,7 +61,8 @@
must_not
=
[]
should
=
[]
cutoff_frequency
=
.
001
minimum_should_match
=
"
40%
"
# https://www.elastic.co/guide/en/elasticsearch/reference/2.4/query-dsl-minimum-should-match.html
minimum_should_match
=
"
1
"
# proximity booster - phrase with slop=50
phrase_query
=
Q
(
'
multi_match
'
,
query
=
query
,
...
...
This diff is collapsed.
Click to expand it.
test/test_parents.py
+
47
−
36
View file @
51da60b6
# flake8: noqa
from
__future__
import
print_function
...
...
@@ -2,3 +2,2 @@
import
hashlib
import
time
...
...
@@ -4,5 +3,4 @@
import
time
from
six
import
text_type
as
unicode
from
cubicweb.devtools
import
testlib
from
cubicweb.cwconfig
import
CubicWebConfiguration
...
...
@@ -6,8 +4,9 @@
from
cubicweb.devtools
import
testlib
from
cubicweb.cwconfig
import
CubicWebConfiguration
from
cubicweb.predicates
import
is_instance
from
cubes.elasticsearch.search_helpers
import
compose_search
from
elasticsearch_dsl
import
Search
from
cubes.elasticsearch.es
import
CUSTOM_ATTRIBUTES
...
...
@@ -9,7 +8,9 @@
from
cubes.elasticsearch.search_helpers
import
compose_search
from
elasticsearch_dsl
import
Search
from
cubes.elasticsearch.es
import
CUSTOM_ATTRIBUTES
from
cubes.elasticsearch.entities
import
IFullTextIndexSerializable
CUSTOM_ATTRIBUTES
[
'
Blog
'
]
=
(
'
title
'
,)
...
...
@@ -14,5 +15,14 @@
CUSTOM_ATTRIBUTES
[
'
Blog
'
]
=
(
'
title
'
,)
class
BlogFTIAdapter
(
IFullTextIndexSerializable
):
__select__
=
(
IFullTextIndexSerializable
.
__select__
&
is_instance
(
'
BlogEntry
'
))
def
update_parent_info
(
self
,
data
,
entity
):
data
[
'
parent
'
]
=
entity
.
entry_of
[
0
].
eid
class
ParentsSearchTC
(
testlib
.
CubicWebTC
):
def
setup_database
(
self
):
...
...
@@ -27,15 +37,16 @@
def
test_parent_search
(
self
):
# self.vid_validators['esearch'] = lambda: None
with
self
.
admin_access
.
cnx
()
as
cnx
:
indexer
=
cnx
.
vreg
[
'
es
'
].
select
(
'
indexer
'
,
cnx
)
indexer
.
get_connection
()
indexer
.
create_index
(
custom_settings
=
{
'
mappings
'
:
{
'
BlogEntry
'
:
{
'
_parent
'
:{
"
type
"
:
"
Blog
"
}},
}
})
test_structure
=
{
u
'
A
'
:
[
u
'
Paris ceci
'
,
u
'
Nantes
'
,
u
'
Toulouse
'
],
u
'
B
'
:
[
u
'
Paris cela
'
],
u
'
C
'
:
[
u
'
Paris autre
'
,
u
'
Paris plage
'
]
with
self
.
temporary_appobjects
(
BlogFTIAdapter
):
indexer
=
cnx
.
vreg
[
'
es
'
].
select
(
'
indexer
'
,
cnx
)
indexer
.
get_connection
()
indexer
.
create_index
(
custom_settings
=
{
'
mappings
'
:
{
'
BlogEntry
'
:
{
'
_parent
'
:
{
"
type
"
:
"
Blog
"
}},
}
})
test_structure
=
{
u
'
A
'
:
[
u
'
Paris ceci
'
,
u
'
Nantes
'
,
u
'
Toulouse
'
],
u
'
B
'
:
[
u
'
Paris cela
'
],
u
'
C
'
:
[
u
'
Paris autre
'
,
u
'
Paris plage
'
],
}
...
...
@@ -41,26 +52,26 @@
}
for
fa_title
,
facomp_contents
in
test_structure
.
items
():
blog
=
cnx
.
create_entity
(
'
Blog
'
,
title
=
fa_title
)
for
facomp_content
in
facomp_contents
:
cnx
.
create_entity
(
'
BlogEntry
'
,
entry_of
=
blog
,
title
=
facomp_content
,
content
=
facomp_content
)
cnx
.
commit
()
time
.
sleep
(
2
)
# TODO find a way to have synchronous operations in unittests
for
query
,
number_of_results
,
first_result
in
((
"
Paris
"
,
3
,
"
C
"
),
(
"
Nantes
"
,
1
,
"
A
"
)):
search
=
compose_search
(
Search
(
)
,
query
,
parents_for
=
"
BlogEnt
ry
"
,
fields
=
[
'
_all
'
]
,
fuzzy
=
True
)
import
json
print
json
.
dumps
(
search
.
to_dict
())
self
.
assertEquals
(
len
(
search
.
execute
()),
number_of_results
)
self
.
assertEquals
(
search
.
execute
().
to_dict
()[
'
hits
'
][
'
hits
'
][
0
][
'
_source
'
][
'
title
'
],
first_result
)
for
fa_title
,
facomp_contents
in
test_structure
.
items
():
blog
=
cnx
.
create_entity
(
'
Blog
'
,
title
=
fa_title
)
for
facomp_content
in
facomp_contents
:
cnx
.
create_entity
(
'
BlogEntry
'
,
entry_of
=
blog
,
title
=
facomp_content
,
content
=
facomp_content
)
cnx
.
commit
()
time
.
sleep
(
2
)
# TODO find a way to have synchronous operations in unittests
for
query
,
number_of_results
,
first_result
in
((
"
Paris
"
,
3
,
"
C
"
),
(
"
Nantes
"
,
1
,
"
A
"
)):
search
=
compose_search
(
Search
(
index
=
self
.
config
[
'
index-name
'
]
,
doc_type
=
'
Blog
'
)
,
que
ry
,
parents_for
=
"
BlogEntry
"
,
fields
=
[
'
_all
'
],
fuzzy
=
True
)
import
json
self
.
assertEquals
(
len
(
search
.
execute
()),
number_of_results
)
self
.
assertEquals
(
search
.
execute
().
to_dict
()[
'
hits
'
][
'
hits
'
][
0
][
'
_source
'
][
'
title
'
],
first_result
)
def
tearDown
(
self
):
with
self
.
admin_access
.
cnx
()
as
cnx
:
...
...
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