search on multiple fields not just package_attr_name or option_name (#145)

fixes #134
This commit is contained in:
Rok Garbas 2020-08-08 01:22:52 +02:00 committed by GitHub
parent cbaf978394
commit bbec7b2a5b
Failed to generate hash of commit
3 changed files with 85 additions and 52 deletions

View file

@ -398,7 +398,17 @@ makeRequest options channel queryRaw from size sort =
|> List.append (should_match 10)
in
Search.makeRequest
(Search.makeRequestBody query from size sort "option" "option_name" "option_name_query" should_queries)
(Search.makeRequestBody query
from
size
sort
"option"
"option_name"
[ "option_name_query"
, "option_description"
]
should_queries
)
("latest-" ++ String.fromInt options.mappingSchemaVersion ++ "-" ++ channel)
decodeResultItemSource
options

View file

@ -505,7 +505,18 @@ makeRequest options channel queryRaw from size sort =
|> List.append (should_match 10)
in
Search.makeRequest
(Search.makeRequestBody query from size sort "package" "package_attr_name" "package_attr_name_query" should_queries)
(Search.makeRequestBody query
from
size
sort
"package"
"package_attr_name"
[ "package_attr_name_query"
, "package_pname"
, "package_description"
]
should_queries
)
("latest-" ++ String.fromInt options.mappingSchemaVersion ++ "-" ++ channel)
decodeResultItemSource
options

View file

@ -734,8 +734,11 @@ filter_by_type type_ =
)
filter_by_query : String -> String -> List (List ( String, Json.Encode.Value ))
filter_by_query field queryRaw =
filter_by_query :
List String
-> String
-> List (List ( String, Json.Encode.Value ))
filter_by_query fields queryRaw =
let
query =
queryRaw
@ -750,11 +753,13 @@ filter_by_query field queryRaw =
isLast =
List.length (String.words query) == i + 1
in
[ if isLast then
( "bool"
if isLast then
[ ( "bool"
, Json.Encode.object
[ ( "should"
, Json.Encode.list Json.Encode.object
(List.concatMap
(\field ->
[ [ ( "match"
, Json.Encode.object
[ ( field
@ -782,10 +787,16 @@ filter_by_query field queryRaw =
]
]
)
fields
)
)
]
)
]
else
List.map
(\field ->
( "match_bool_prefix"
, Json.Encode.object
[ ( field
@ -798,7 +809,8 @@ filter_by_query field queryRaw =
)
]
)
]
)
fields
)
@ -809,10 +821,10 @@ makeRequestBody :
-> Sort
-> String
-> String
-> String
-> List String
-> List (List ( String, Json.Encode.Value ))
-> Http.Body
makeRequestBody query from sizeRaw sort type_ sort_field query_field should_queries =
makeRequestBody query from sizeRaw sort type_ sort_field query_fields should_queries =
let
-- you can not request more then 10000 results otherwise it will return 404
size =
@ -839,7 +851,7 @@ makeRequestBody query from sizeRaw sort type_ sort_field query_field should_quer
, Json.Encode.list Json.Encode.object
(List.append
[ [ filter_by_type type_ ] ]
(filter_by_query query_field query)
(filter_by_query query_fields query)
)
)
, ( "should"