space should present an OR operation in query (#150)
filtering part of the query was messed up when I added search over multiple fields. fixes #147 fixes #149
This commit is contained in:
parent
818074f626
commit
91527f1deb
|
@ -165,8 +165,8 @@ viewResultItem channel show item =
|
|||
-- DEBUG: |> List.append
|
||||
-- DEBUG: [ tr []
|
||||
-- DEBUG: [ td [ colspan 1 ]
|
||||
-- DEBUG: [ p [] [ text <| "score: " ++ String.fromFloat item.score ]
|
||||
-- DEBUG: , p []
|
||||
-- DEBUG: [ div [] [ text <| "score: " ++ String.fromFloat (Maybe.withDefault 0 item.score) ]
|
||||
-- DEBUG: , div []
|
||||
-- DEBUG: [ text <|
|
||||
-- DEBUG: "matched queries: "
|
||||
-- DEBUG: , ul []
|
||||
|
|
|
@ -737,23 +737,21 @@ filter_by_type type_ =
|
|||
filter_by_query :
|
||||
List String
|
||||
-> String
|
||||
-> List (List ( String, Json.Encode.Value ))
|
||||
-> ( String, Json.Encode.Value )
|
||||
filter_by_query fields queryRaw =
|
||||
let
|
||||
query =
|
||||
queryRaw
|
||||
|> String.trim
|
||||
in
|
||||
query
|
||||
|> String.replace "." " "
|
||||
( "bool"
|
||||
, Json.Encode.object
|
||||
[ ( "should"
|
||||
, Json.Encode.list Json.Encode.object
|
||||
(query
|
||||
|> String.words
|
||||
|> List.indexedMap
|
||||
(\i query_word ->
|
||||
let
|
||||
isLast =
|
||||
List.length (String.words query) == i + 1
|
||||
in
|
||||
if isLast then
|
||||
[ ( "bool"
|
||||
, Json.Encode.object
|
||||
[ ( "should"
|
||||
|
@ -766,7 +764,7 @@ filter_by_query fields queryRaw =
|
|||
, Json.Encode.object
|
||||
[ ( "query", Json.Encode.string query_word )
|
||||
, ( "fuzziness", Json.Encode.string "1" )
|
||||
, ( "_name", Json.Encode.string <| "filter_queries_" ++ String.fromInt (i + 1) ++ "_should_match" )
|
||||
, ( "_name", Json.Encode.string <| "filter_queries_" ++ String.fromInt i ++ "_should_match" )
|
||||
]
|
||||
)
|
||||
]
|
||||
|
@ -793,25 +791,11 @@ filter_by_query fields queryRaw =
|
|||
]
|
||||
)
|
||||
]
|
||||
|
||||
else
|
||||
List.map
|
||||
(\field ->
|
||||
( "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) ++ "_prefix"
|
||||
)
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
fields
|
||||
)
|
||||
|
||||
|
||||
makeRequestBody :
|
||||
|
@ -849,10 +833,9 @@ makeRequestBody query from sizeRaw sort type_ sort_field query_fields should_que
|
|||
, Json.Encode.object
|
||||
[ ( "filter"
|
||||
, Json.Encode.list Json.Encode.object
|
||||
(List.append
|
||||
[ [ filter_by_type type_ ] ]
|
||||
(filter_by_query query_fields query)
|
||||
)
|
||||
[ [ filter_by_type type_ ]
|
||||
, [ filter_by_query query_fields query ]
|
||||
]
|
||||
)
|
||||
, ( "should"
|
||||
, Json.Encode.list Json.Encode.object should_queries
|
||||
|
|
Loading…
Reference in a new issue