Bool query (#36)

* Use unsigned boto s3 requests

Without this change you need s3 credentials, even though the bucket is public

* Use custom attrname analyzer

* Adapt query to new schema

Use pname/pversion to not clash with elasticsearch parsing of version

* Elasticsearch: Start work on new bool query

* encode query string for bool query

Co-authored-by: adisbladis <adisbladis@gmail.com>
This commit is contained in:
Rok Garbas 2020-05-20 13:01:29 +02:00 committed by GitHub
parent 042cb40a8e
commit f4b7ebca1e
Failed to generate hash of commit

View file

@ -443,45 +443,106 @@ makeRequestBody :
-> Http.Body -> Http.Body
makeRequestBody field query from size = makeRequestBody field query from size =
-- Prefix Query -- Prefix Query
-- example query for "python"
-- { -- {
-- "from": 0,
-- "size": 10,
-- "query": { -- "query": {
-- "bool": {
-- "should": [
-- {
-- "multi_match": { -- "multi_match": {
-- "query": "python37Packages.requests", -- "query": "python",
-- "boost": 1,
-- "fields": [ -- "fields": [
-- "attr_name.raw", -- "attr_name.raw",
-- "attr_name", -- "attr_name"
-- "pname", -- ],
-- "pversion", -- "type": "most_fields"
-- "description", -- }
-- "longDescription" -- },
-- {
-- "term": {
-- "pname": {
-- "value": "python",
-- "boost": 2
-- }
-- }
-- },
-- {
-- "term": {
-- "pversion": {
-- "value": "python",
-- "boost": 0.2
-- }
-- }
-- },
-- {
-- "term": {
-- "description": {
-- "value": "python",
-- "boost": 0.3
-- }
-- }
-- },
-- {
-- "term": {
-- "longDescription": {
-- "value": "python",
-- "boost": 0.1
-- }
-- }
-- }
-- ] -- ]
-- } -- }
-- } -- }
Http.jsonBody -- }
(Json.Encode.object let
listIn name type_ value =
[ ( name, Json.Encode.list type_ value ) ]
objectIn name value =
[ ( name, Json.Encode.object value ) ]
encodeTerm ( name, boost ) =
[ ( "term"
, Json.Encode.object
[ ( name
, Json.Encode.object
[ ( "value", Json.Encode.string query )
, ( "boost", Json.Encode.float boost )
]
)
]
)
]
in
[ ( "pname", 2.0 )
, ( "pversion", 0.2 )
, ( "description", 0.3 )
, ( "longDescription", 0.1 )
]
|> List.map encodeTerm
|> List.append
[ [ "attr_name.raw"
, "attr_name"
]
|> listIn "fields" Json.Encode.string
|> List.append
[ ( "query", Json.Encode.string query )
, ( "boost", Json.Encode.float 1.0 )
]
|> objectIn "multi_match"
]
|> listIn "should" Json.Encode.object
|> objectIn "bool"
|> objectIn "query"
|> List.append
[ ( "from", Json.Encode.int from ) [ ( "from", Json.Encode.int from )
, ( "size", Json.Encode.int size ) , ( "size", Json.Encode.int size )
, ( "query"
, Json.Encode.object
[ ( "multi_match"
, Json.Encode.object
[ ( "query", Json.Encode.string query )
, ( "fields"
, Json.Encode.list Json.Encode.string
[ "attr_name.raw"
, "attr_name"
, "pname"
, "pversion"
, "description"
, "longDescription"
] ]
) |> Json.Encode.object
] |> Http.jsonBody
)
]
)
]
)
makeRequest : makeRequest :