Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: field selection for search #377

Merged
merged 1 commit into from Jul 22, 2022
Merged

feat: field selection for search #377

merged 1 commit into from Jul 22, 2022

Conversation

adilansari
Copy link
Contributor

  • Ability to request certain document fields from search results, by inclusion or exclusion:
{
    "q": "running",
    "fields": {"title": false, "price": false}
}
  • Fixed a minor bug where facet sizes was not being respected in response. Only the max size was being honored

@JigarJoshi
Copy link
Contributor

JigarJoshi commented Jul 21, 2022

do we need true/false explicitly? how about this

    "fields": ["title", "price"]

and for the other scenario

    "excluded_fields": ["author", "language"]

what do you think?

@JigarJoshi
Copy link
Contributor

please add test exercising this code path.

Facets Facets
PageSize int
WrappedF *filter.WrappedFilter
FieldSelection *read.FieldFactory
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just have a simple list, no need to have it as a map because I don't see in the future if we need to add any functionality inside the fields object

// apply the field selection
if p.fieldSelection != nil {
newValue, err := p.fieldSelection.Apply(rawData)
if ulog.E(err) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about user input is a list but in code, we can build the fields using read.FieldFactory then we can still use this method but user input is simple.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did make the change but doesn't look too intuitive to implicitly assume fields array to inclusion list. It may not appear intuitive if a user is building [a, b] for inclusion list and [a: false, b: false] for exclusion. Even if this array is easy to use, we should rather have include and exclude explicitly

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I was not saying it to have [a: false, b: false]. I was saying to just have an array [a, b], similarly for exclude it will be an array.

@@ -37,6 +38,37 @@ func BuildFields(reqFields jsoniter.RawMessage) (*FieldFactory, error) {
factory.Include = make(map[string]Field)
factory.Exclude = make(map[string]Field)

var v interface{}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allowing read fields input to be an array, will update user facing documentation for both APIs separately

@adilansari
Copy link
Contributor Author

do we need true/false explicitly? how about this

    "fields": ["title", "price"]

and for the other scenario

    "excluded_fields": ["author", "language"]

what do you think?

So should we make an API change now for both read and search to accept, include/exclude or just implicitly assume fields array to be inclusion list

@himank
Copy link
Collaborator

himank commented Jul 22, 2022

do we need true/false explicitly? how about this

    "fields": ["title", "price"]

and for the other scenario

    "excluded_fields": ["author", "language"]

what do you think?

So should we make an API change now for both read and search to accept, include/exclude or just implicitly assume fields array to be inclusion list

So we don't need to make any changes to read because read supports expressions as a value which the current implementation only supports true/false/1/0 but we will be extending it later to support arithmetic operations etc.

For search, the value is not an expression. The only value for it would be true/false/1/0 or separating it out as an include/exclude list.

Thinking more about it, I think either approach should be fine. to support it as an array with explicit exclude/include or to have a map.

// it's something else
err = api.Errorf(api.Code_INVALID_ARGUMENT, "fields selection can only be array or object")
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, remove the extra line.

}

var err error
switch v := v.(type) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will we have in the open API spec? Object or array?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it is confusing, I am fine to stick with having it as an object to avoid any confusion and if needed in clients we can have an array.

@adilansari
Copy link
Contributor Author

If we have to separate this from Read api (because read will evolve into aggregations etc.), I'd rather make a change now to include/exclude

@adilansari
Copy link
Contributor Author

This PR now only has fix for facet sizes, I'll send a separate one for API change

@codecov-commenter
Copy link

Codecov Report

Merging #377 (0258e26) into main (797dd7f) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #377      +/-   ##
==========================================
- Coverage   28.70%   28.68%   -0.03%     
==========================================
  Files          66       66              
  Lines        6936     6941       +5     
==========================================
  Hits         1991     1991              
- Misses       4718     4723       +5     
  Partials      227      227              
Impacted Files Coverage Δ
server/services/v1/search_reader.go 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 797dd7f...0258e26. Read the comment docs.

@adilansari adilansari merged commit 72a86de into main Jul 22, 2022
@adilansari adilansari deleted the facet-size branch July 22, 2022 16:34
@tigrisdata-argocd-bot
Copy link
Collaborator

🎉 This PR is included in version 1.0.0-alpha.24 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@tigrisdata-argocd-bot
Copy link
Collaborator

🎉 This PR is included in version 1.0.0-beta.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants