Skip to content

Refactored the term suggestion builder for the query refactoring effort#16278

Merged
abeyad merged 1 commit intoelastic:feature-suggest-refactoringfrom
abeyad:feature-suggest-refactoring
Feb 3, 2016
Merged

Refactored the term suggestion builder for the query refactoring effort#16278
abeyad merged 1 commit intoelastic:feature-suggest-refactoringfrom
abeyad:feature-suggest-refactoring

Conversation

@abeyad
Copy link
Copy Markdown

@abeyad abeyad commented Jan 27, 2016

Added the term suggestion builder's serialization/deserialization and
equals/hashCode methods.

@areek areek added review :Search Relevance/Suggesters "Did you mean" and suggestions as you type labels Jan 27, 2016
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like a leftover indeed an I think it can be removed, but maybe @javanna can take a second look?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what is unused is unused :) I have no idea how it became unused though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think NamedWriteableAwareStreamInput was introduced just a bit later. Only my guess.

@cbuescher
Copy link
Copy Markdown
Member

Looks great already, I left some comments and maybe @areek wants to have another look too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A value if 0 seems to be okay here. At least there are some tests in SuggestSearchTests (unfortunately in the lang-mustache module) that use that and now fail with an exception.

@abeyad abeyad force-pushed the feature-suggest-refactoring branch from b927ad1 to 7f17e32 Compare January 30, 2016 04:27
@abeyad
Copy link
Copy Markdown
Author

abeyad commented Jan 30, 2016

@cbuescher I made the changes we discussed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@s1monw Wanted to get your input on the method below. Its meant to be a convenience method for taking an input string (e.g. a JSON parameter) and converting it to an enum, in the situation where the enum element does not have the same name as the input string (and hence, can't use Enum.valueOf). A common case is where we name the enum element in all upper case but the string value is in lower case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like the trick here but I think it's too much magic after all. Can we stick to switch / case and ordinals - it's something everybody understands without reading up on it? WDYT

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Plus I just realized that sometimes we have more than one variant of an enum value in the query DSL (e.g. camel casing etc.) that needs to be mapped to one enum. For example, the StringDistance currently allows both "damerau_levenshtein" and "damerauLevenshtein". This might be something to get rid of, but in the meantime we need to support it I think.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@s1monw @cbuescher Good points, especially with the multiple variants for any given enum value that Christoph mentioned, this interface provides no added benefit then. I'll take it out.

@cbuescher
Copy link
Copy Markdown
Member

@abeyad thanks, looks very good now. I left two minor comments, also lets wait on input on the NamedEnum, then I think this is ready for merging.

@abeyad abeyad force-pushed the feature-suggest-refactoring branch from 7f17e32 to c4365c6 Compare February 1, 2016 22:19
@abeyad
Copy link
Copy Markdown
Author

abeyad commented Feb 1, 2016

@cbuescher @colings86 @areek I updated the PR with the latest commits that address the code review comments. One thing to note is that I also added a AbstractWriteableEnumTestCase that reduces the amount of boilerplate code for writing tests for enums that implement Writeable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This probably shouldn't be nullable. We have the zero-arg constructor above for when a no name is needed so maybe we should throw an exception if the name is null here so the user is alerted to the fact that the variable they are passing in is null?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good point, but my personal opinion here is that if the value is optional we should allow null. It would be different if this can overwrite a default settings, but thats not the case here. I'm not a big fan of the annotation though.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I figured the annotation would declare the intent clearly. I think the bigger issue is deciding if name can be null or not and then build a consistent API for the builder that allows to set the value consistently (i.e. everywhere the property can either be null or everywhere it is prohibited from being null). Just my two cents.

@abeyad abeyad force-pushed the feature-suggest-refactoring branch from c4365c6 to 2312c11 Compare February 2, 2016 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Search Relevance/Suggesters "Did you mean" and suggestions as you type :Search/Search Search-related issues that do not fall into other categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants