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

Add a new static method for KeywordField#newSetQuery to support collections parameter #12243

Closed
slow-J opened this issue Apr 26, 2023 · 8 comments · Fixed by #12837
Closed

Add a new static method for KeywordField#newSetQuery to support collections parameter #12243

slow-J opened this issue Apr 26, 2023 · 8 comments · Fixed by #12837

Comments

@slow-J
Copy link
Contributor

slow-J commented Apr 26, 2023

Description

Currently, the KeywordField class provides a public static method newSetQuery(String field, BytesRef... values). However, this method only supports varargs parameter for values. I would like to propose adding a new static method that allows for a collections parameter for values, as this would provide greater flexibility.

Proposed method signature:
public static Query newSetQuery(String field, Collection<BytesRef> values)

I am willing to make the changes and submit a pull request.
Please let me know if there are any concerns or feedback. Thank you!

@rmuir
Copy link
Member

rmuir commented Apr 26, 2023

"flexibility" is usually a dirty word when it comes to apis, is there a better explanation of the use-case?

Especially given that Collection has .toArray already, it seems really easy for the user to use as-is?

@rmuir
Copy link
Member

rmuir commented Apr 26, 2023

and frankly, i have big concerns that this method will somehow warp into something other than calling .toArray to help the user.

database users be database users and this kind of complexity has crept in here before.

Let's keep it simple with basic arrays.

@slow-J
Copy link
Contributor Author

slow-J commented Apr 26, 2023

Thanks for the quick reply @rmuir , I'll try explain the use case better.

Calling the existing newSetQuery takes the array and constructs: 1,2 TermInSetQueries which both then wrap the array with a list Arrays.asList(terms).

So in the case of having a List of BytesRef, we would first call .toArray, and then TermInSetQuery immediately calls Arrays.asList.
This seems a bit redundant to me, since there are existing TermInSetQuery constructors that take the collection parameters 1, 2.

The new newSetQuery(String field, Collection<BytesRef> values) method would simply call the TermInSetQuery constructors with the collections parameter.

@mikemccand
Copy link
Member

It is sort of odd to take an ordered collection (BytesRef[] currently), since the order of the incoming terms has no meaning/requirement?

Or does KeywordField require that the user pre-sort the incoming BytesRefs to newSetQuery?

@rmuir
Copy link
Member

rmuir commented Jul 18, 2023

I don't think the fact that TermInSetQuery has a Collection ctor should impact this at all. Maybe that should be removed?

@mikemccand
Copy link
Member

I don't think the fact that TermInSetQuery has a Collection ctor should impact this at all. Maybe that should be removed?

+1

It's weird to take both array and Collection when the API is just going to do the obvious conversion that a caller would do? We should somehow be consistent here about such "sugar" APIs.

But if we are going to pick one, shouldn't it be Collection for these two cases, since order does not matter? Taking an array implies that order might be significant, but (I think?) order does not matter for KeywordField.newSetQuery nor for TermInSetQuery ctor?

I don't feel strongly though (Collection vs array) ... but I do agree we should be consistent.

@slow-J
Copy link
Contributor Author

slow-J commented Nov 23, 2023

I don't think the fact that TermInSetQuery has a Collection ctor should impact this at all. Maybe that should be removed?

+1

It's weird to take both array and Collection when the API is just going to do the obvious conversion that a caller would do? We should somehow be consistent here about such "sugar" APIs.

But if we are going to pick one, shouldn't it be Collection for these two cases, since order does not matter? Taking an array implies that order might be significant, but (I think?) order does not matter for KeywordField.newSetQuery nor for TermInSetQuery ctor?

I don't feel strongly though (Collection vs array) ... but I do agree we should be consistent.

Thanks Mike, to progress the discussion I opened a PR to remove the TermInSetQuery array ctor and change the KeywordField.newSetQuery values param to Collections

@gsmiller
Copy link
Contributor

+1 to shrinking the API surface of the TermInSetQuery ctors and getting rid of the varargs flavors since they're pure syntactic sugar. Looks like #12837 is the related PR, so left a small comment over there. Thanks @slow-J !

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

Successfully merging a pull request may close this issue.

4 participants