search on multiple fields not just package_attr_name or option_name (#145)
fixes #134
This commit is contained in:
parent
cbaf978394
commit
bbec7b2a5b
|
@ -398,7 +398,17 @@ makeRequest options channel queryRaw from size sort =
|
||||||
|> List.append (should_match 10)
|
|> List.append (should_match 10)
|
||||||
in
|
in
|
||||||
Search.makeRequest
|
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)
|
("latest-" ++ String.fromInt options.mappingSchemaVersion ++ "-" ++ channel)
|
||||||
decodeResultItemSource
|
decodeResultItemSource
|
||||||
options
|
options
|
||||||
|
|
|
@ -505,7 +505,18 @@ makeRequest options channel queryRaw from size sort =
|
||||||
|> List.append (should_match 10)
|
|> List.append (should_match 10)
|
||||||
in
|
in
|
||||||
Search.makeRequest
|
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)
|
("latest-" ++ String.fromInt options.mappingSchemaVersion ++ "-" ++ channel)
|
||||||
decodeResultItemSource
|
decodeResultItemSource
|
||||||
options
|
options
|
||||||
|
|
112
src/Search.elm
112
src/Search.elm
|
@ -734,8 +734,11 @@ filter_by_type type_ =
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
filter_by_query : String -> String -> List (List ( String, Json.Encode.Value ))
|
filter_by_query :
|
||||||
filter_by_query field queryRaw =
|
List String
|
||||||
|
-> String
|
||||||
|
-> List (List ( String, Json.Encode.Value ))
|
||||||
|
filter_by_query fields queryRaw =
|
||||||
let
|
let
|
||||||
query =
|
query =
|
||||||
queryRaw
|
queryRaw
|
||||||
|
@ -750,55 +753,64 @@ filter_by_query field queryRaw =
|
||||||
isLast =
|
isLast =
|
||||||
List.length (String.words query) == i + 1
|
List.length (String.words query) == i + 1
|
||||||
in
|
in
|
||||||
[ if isLast then
|
if isLast then
|
||||||
( "bool"
|
[ ( "bool"
|
||||||
, Json.Encode.object
|
, Json.Encode.object
|
||||||
[ ( "should"
|
[ ( "should"
|
||||||
, Json.Encode.list Json.Encode.object
|
, Json.Encode.list Json.Encode.object
|
||||||
[ [ ( "match"
|
(List.concatMap
|
||||||
, Json.Encode.object
|
(\field ->
|
||||||
[ ( field
|
[ [ ( "match"
|
||||||
, Json.Encode.object
|
, Json.Encode.object
|
||||||
[ ( "query", Json.Encode.string query_word )
|
[ ( field
|
||||||
, ( "fuzziness", Json.Encode.string "1" )
|
, Json.Encode.object
|
||||||
, ( "_name", Json.Encode.string <| "filter_queries_" ++ String.fromInt (i + 1) ++ "_should_match" )
|
[ ( "query", Json.Encode.string query_word )
|
||||||
]
|
, ( "fuzziness", Json.Encode.string "1" )
|
||||||
)
|
, ( "_name", Json.Encode.string <| "filter_queries_" ++ String.fromInt (i + 1) ++ "_should_match" )
|
||||||
]
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
, [ ( "match_bool_prefix"
|
||||||
|
, Json.Encode.object
|
||||||
|
[ ( field
|
||||||
|
, Json.Encode.object
|
||||||
|
[ ( "query", Json.Encode.string query_word )
|
||||||
|
, ( "_name"
|
||||||
|
, Json.Encode.string <| "filter_queries_" ++ String.fromInt (i + 1) ++ "_should_prefix"
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
fields
|
||||||
)
|
)
|
||||||
]
|
)
|
||||||
, [ ( "match_bool_prefix"
|
]
|
||||||
, Json.Encode.object
|
)
|
||||||
[ ( field
|
]
|
||||||
, Json.Encode.object
|
|
||||||
[ ( "query", Json.Encode.string query_word )
|
|
||||||
, ( "_name"
|
|
||||||
, Json.Encode.string <| "filter_queries_" ++ String.fromInt (i + 1) ++ "_should_prefix"
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
]
|
|
||||||
]
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
else
|
else
|
||||||
( "match_bool_prefix"
|
List.map
|
||||||
, Json.Encode.object
|
(\field ->
|
||||||
[ ( field
|
( "match_bool_prefix"
|
||||||
, Json.Encode.object
|
, Json.Encode.object
|
||||||
[ ( "query", Json.Encode.string query_word )
|
[ ( field
|
||||||
, ( "_name"
|
, Json.Encode.object
|
||||||
, Json.Encode.string <| "filter_queries_" ++ String.fromInt (i + 1) ++ "_prefix"
|
[ ( "query", Json.Encode.string query_word )
|
||||||
|
, ( "_name"
|
||||||
|
, Json.Encode.string <| "filter_queries_" ++ String.fromInt (i + 1) ++ "_prefix"
|
||||||
|
)
|
||||||
|
]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
]
|
)
|
||||||
)
|
fields
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -809,10 +821,10 @@ makeRequestBody :
|
||||||
-> Sort
|
-> Sort
|
||||||
-> String
|
-> String
|
||||||
-> String
|
-> String
|
||||||
-> String
|
-> List String
|
||||||
-> List (List ( String, Json.Encode.Value ))
|
-> List (List ( String, Json.Encode.Value ))
|
||||||
-> Http.Body
|
-> 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
|
let
|
||||||
-- you can not request more then 10000 results otherwise it will return 404
|
-- you can not request more then 10000 results otherwise it will return 404
|
||||||
size =
|
size =
|
||||||
|
@ -839,7 +851,7 @@ makeRequestBody query from sizeRaw sort type_ sort_field query_field should_quer
|
||||||
, Json.Encode.list Json.Encode.object
|
, Json.Encode.list Json.Encode.object
|
||||||
(List.append
|
(List.append
|
||||||
[ [ filter_by_type type_ ] ]
|
[ [ filter_by_type type_ ] ]
|
||||||
(filter_by_query query_field query)
|
(filter_by_query query_fields query)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
, ( "should"
|
, ( "should"
|
||||||
|
|
Loading…
Reference in a new issue