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:
Rok Garbas 2020-08-21 21:23:21 +02:00 committed by GitHub
parent 818074f626
commit 91527f1deb
Failed to generate hash of commit
2 changed files with 51 additions and 68 deletions

View file

@ -165,8 +165,8 @@ viewResultItem channel show item =
-- DEBUG: |> List.append -- DEBUG: |> List.append
-- DEBUG: [ tr [] -- DEBUG: [ tr []
-- DEBUG: [ td [ colspan 1 ] -- DEBUG: [ td [ colspan 1 ]
-- DEBUG: [ p [] [ text <| "score: " ++ String.fromFloat item.score ] -- DEBUG: [ div [] [ text <| "score: " ++ String.fromFloat (Maybe.withDefault 0 item.score) ]
-- DEBUG: , p [] -- DEBUG: , div []
-- DEBUG: [ text <| -- DEBUG: [ text <|
-- DEBUG: "matched queries: " -- DEBUG: "matched queries: "
-- DEBUG: , ul [] -- DEBUG: , ul []

View file

@ -737,81 +737,65 @@ filter_by_type type_ =
filter_by_query : filter_by_query :
List String List String
-> String -> String
-> List (List ( String, Json.Encode.Value )) -> ( String, Json.Encode.Value )
filter_by_query fields queryRaw = filter_by_query fields queryRaw =
let let
query = query =
queryRaw queryRaw
|> String.trim |> String.trim
in in
query ( "bool"
|> String.replace "." " " , Json.Encode.object
|> String.words [ ( "should"
|> List.indexedMap , Json.Encode.list Json.Encode.object
(\i query_word -> (query
let |> String.words
isLast = |> List.indexedMap
List.length (String.words query) == i + 1 (\i query_word ->
in [ ( "bool"
if isLast then , Json.Encode.object
[ ( "bool" [ ( "should"
, Json.Encode.object , Json.Encode.list Json.Encode.object
[ ( "should" (List.concatMap
, Json.Encode.list Json.Encode.object (\field ->
(List.concatMap [ [ ( "match"
(\field -> , Json.Encode.object
[ [ ( "match" [ ( field
, Json.Encode.object , Json.Encode.object
[ ( field [ ( "query", Json.Encode.string query_word )
, Json.Encode.object , ( "fuzziness", Json.Encode.string "1" )
[ ( "query", Json.Encode.string query_word ) , ( "_name", Json.Encode.string <| "filter_queries_" ++ String.fromInt i ++ "_should_match" )
, ( "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"
) )
] ]
) )
]
, [ ( "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
] )
) )
fields ]
)
) )
] ]
)
]
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 : makeRequestBody :
@ -849,10 +833,9 @@ makeRequestBody query from sizeRaw sort type_ sort_field query_fields should_que
, Json.Encode.object , Json.Encode.object
[ ( "filter" [ ( "filter"
, Json.Encode.list Json.Encode.object , Json.Encode.list Json.Encode.object
(List.append [ [ filter_by_type type_ ]
[ [ filter_by_type type_ ] ] , [ filter_by_query query_fields query ]
(filter_by_query query_fields query) ]
)
) )
, ( "should" , ( "should"
, Json.Encode.list Json.Encode.object should_queries , Json.Encode.list Json.Encode.object should_queries