Repository navigation
Allow extra searchable metadata in package - #351
Conversation
|
How should we handle bringing in the ability to match on extra path Lets say we have several packages with extra package metadata defined like this: How to search for nerves packages where the key foo in extra = bar |
|
Something like this maybe? https://hex.pm/packages?_utf8=%E2%9C%93&search=nerves&sort=downloads&extra_path[]=foo&extra_path[]=bar&extra_value=baz We need to be able to support nested paths, I think. |
| execute """ | ||
| CREATE INDEX packages_extra_text ON | ||
| packages USING GIN (to_tsvector('english', regexp_replace((meta->'extra')::text, '/', ' '))) | ||
| """ |
There was a problem hiding this comment.
This will not work if you want to specify paths so we can't use full text search unfortunately. This code is encoding the json as text so you will have a string with "{...}".
If we wan't full text search we need to concatenate all text inside the nested json values. I think exact value search would be better.
|
I started putting in some test information. Should we only support nested paths, or can we also support nested lists |
|
nested paths are pretty simple I was thinking we could split the valiue of the extra path param with do we or can we support nested lists. In the example above if trying to select form a list |
|
I've been looking more at JSON value indexing at https://www.postgresql.org/docs/9.5/static/datatype-json.html. It seems we can only query using the index on top level values, but we can query on array elements. If we want to query on nested elements we need to flatten the JSON object inside the index expression.
This assumes that the keys cannot contain
We can support that on the first "level" of a list but nesting the path inside lists would be tricky so I don't think we should allow that. |
|
We can query on one level of nesting if the nested element is an array as shown in the example from the documentation: |
|
That syntax works really well for both the value being a list or a value. I think that the strategy is: nested maps nested lists not maps in lists As per the params Is it safe to enum params and find the one with the key that starts_with? "extra:" and then break the path off the remainder of the key. This would let us do |
Keep in mind that this would require us to flatten json object in the index expression (if I understood the postgres docs correctly).
It would be possible, but with |
|
Im getting caught up in trying to compose search in terms of a text fragments in to a query. After a talk with Eric, we determined that it would make more sense to incorporate searching on extra into the standard search behavior. For example Current Search New Search
backwards compatibility is achieved by converting a string with no keywords ("name", "description", "extra") into the above example. The problems start to arise when introducing extra
When parsed, the AND takes precedence so description AND extra... OR name. To get around this we would have to introduce
This is where things start to feel like they are getting out of hand. Composing My main use case for this feature is to allow filtering search results so we can list all packages where name like 'nerves_pkg_%' and extra:{"nerves": {"binaries": [...]}} contains "this_binary". Offering everything through an expressive search is feeling daunting. Wondering if anyone has an recommendations or different angles on the best implementation for everyone. |
|
for updated notes, we also ran experiments on how to execute using a single operand for jsonb. These produce viable results |
|
You can make it always AND as long as we keep the current behaviour of ORing name and description when doing the "standard" search. |
|
Ready for another pass |
|
I changed the search semantics a little for name:v to expect the wildcards to be passed in as part of the name:nerves% rebased and resolved conflicts |
| def index(conn, params) do | ||
| page = HexWeb.Utils.safe_int(params["page"]) | ||
| search = HexWeb.Utils.safe_search(params["search"]) | ||
| search = params["search"] |
There was a problem hiding this comment.
We still need the conversion to nil for "". Maybe add a new function to Package that only does the String.replace?
WIP
Added fields and tests to have package_metadata contain extra map.
Todo:
extend search API to pass object path and search words
Tracked alongside
hexpm/hex#234
hexpm/specifications#6