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"
-- { -- {
-- "query": { -- "from": 0,
-- "multi_match" : { -- "size": 10,
-- "query": "python37Packages.requests", -- "query": {
-- "bool": {
-- "should": [
-- {
-- "multi_match": {
-- "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 -- }
[ ( "from", Json.Encode.int from ) let
, ( "size", Json.Encode.int size ) listIn name type_ value =
, ( "query" [ ( name, Json.Encode.list type_ value ) ]
objectIn name value =
[ ( name, Json.Encode.object value ) ]
encodeTerm ( name, boost ) =
[ ( "term"
, Json.Encode.object , Json.Encode.object
[ ( "multi_match" [ ( name
, Json.Encode.object , Json.Encode.object
[ ( "query", Json.Encode.string query ) [ ( "value", Json.Encode.string query )
, ( "fields" , ( "boost", Json.Encode.float boost )
, Json.Encode.list Json.Encode.string
[ "attr_name.raw"
, "attr_name"
, "pname"
, "pversion"
, "description"
, "longDescription"
]
)
] ]
) )
] ]
) )
] ]
) 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 )
, ( "size", Json.Encode.int size )
]
|> Json.Encode.object
|> Http.jsonBody
makeRequest : makeRequest :