Skip to content

Commit

Permalink
packages aggs fields
Browse files Browse the repository at this point in the history
  • Loading branch information
garbas committed Dec 4, 2020
1 parent 27ff900 commit 7f68609
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
16
17
4 changes: 4 additions & 0 deletions import-scripts/import_scripts/channel.py
Expand Up @@ -148,6 +148,7 @@
"type": "nested",
"properties": {"fullName": {"type": "text"}, "url": {"type": "text"}},
},
"package_license_set": {"type": "keyword"},
"package_maintainers": {
"type": "nested",
"properties": {
Expand All @@ -156,6 +157,7 @@
"github": {"type": "text"},
},
},
"package_maintainers_set": {"type": "keyword"},
"package_platforms": {"type": "keyword"},
"package_position": {"type": "text"},
"package_homepage": {"type": "keyword"},
Expand Down Expand Up @@ -486,7 +488,9 @@ def gen():
package_longDescription=package_longDescription,
package_longDescription_reverse=field_reverse(package_longDescription),
package_license=licenses,
package_license_set=[i["fullName"] for i in licenses],
package_maintainers=maintainers,
package_maintainers_set=[i["name"] for i in maintainers if i["name"]],
package_platforms=[i for i in platforms if i],
package_position=position,
package_homepage=data["meta"].get("homepage"),
Expand Down
1 change: 1 addition & 0 deletions src/Page/Options.elm
Expand Up @@ -283,6 +283,7 @@ makeRequest options channel query from size sort =
sort
"option"
"option_name"
[]
[ ( "option_name", 6.0 )
, ( "option_name_query", 3.0 )
, ( "option_description", 1.0 )
Expand Down
5 changes: 5 additions & 0 deletions src/Page/Packages.elm
Expand Up @@ -407,6 +407,11 @@ makeRequest options channel query from size sort =
sort
"package"
"package_attr_name"
[ "package_attr_set"
, "package_license_set"
, "package_maintainers_set"
, "package_platform"
]
[ ( "package_attr_name", 9.0 )
, ( "package_pname", 6.0 )
, ( "package_attr_name_query", 4.0 )
Expand Down
72 changes: 71 additions & 1 deletion src/Search.elm
Expand Up @@ -346,6 +346,47 @@ sortBy =
]


toAggs :
List String
-> ( String, Json.Encode.Value )
toAggs aggsFields =
let
fields =
List.map
(\field ->
( field
, Json.Encode.object
[ ( "terms"
, Json.Encode.object
[ ( "field"
, Json.Encode.string field
)
]
)
]
)
)
aggsFields

allFields =
[ ( "all"
, Json.Encode.object
[ ( "global"
, Json.Encode.object []
)
, ( "aggs"
, Json.Encode.object fields
)
]
)
]
in
( "aggs"
, Json.Encode.object <|
List.append fields allFields
)


toSortQuery :
Sort
-> String
Expand Down Expand Up @@ -751,9 +792,10 @@ makeRequestBody :
-> Sort
-> String
-> String
-> List String
-> List ( String, Float )
-> Http.Body
makeRequestBody query from sizeRaw sort type_ sortField fields =
makeRequestBody query from sizeRaw sort type_ sortField aggsFields fields =
let
-- you can not request more then 10000 results otherwise it will return 404
size =
Expand All @@ -772,6 +814,34 @@ makeRequestBody query from sizeRaw sort type_ sortField fields =
, Json.Encode.int size
)
, toSortQuery sort sortField
, toAggs aggsFields

--, ( "aggs"
-- , Json.Encode.object
-- [ ( "package_attr_set"
-- , Json.Encode.object
-- [ ( "terms"
-- , Json.Encode.object
-- [ ( "field"
-- , Json.Encode.string "package_attr_set"
-- )
-- ]
-- )
-- ]
-- )
-- , ( "package_license_set"
-- , Json.Encode.object
-- [ ( "terms"
-- , Json.Encode.object
-- [ ( "field"
-- , Json.Encode.string "package_license_set"
-- )
-- ]
-- )
-- ]
-- )
-- ]
-- )
, ( "query"
, Json.Encode.object
[ ( "bool"
Expand Down

0 comments on commit 7f68609

Please sign in to comment.