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
FunctionScore: RandomScoreFunction now accepts long, as well a strings. #8311
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ | |
*/ | ||
public class RandomScoreFunctionBuilder extends ScoreFunctionBuilder { | ||
|
||
private Integer seed = null; | ||
private Object seed = null; | ||
|
||
public RandomScoreFunctionBuilder() { | ||
} | ||
|
@@ -49,11 +49,33 @@ public RandomScoreFunctionBuilder seed(int seed) { | |
return this; | ||
} | ||
|
||
/** | ||
* seed variant taking a long value. | ||
* @see {@link #seed(int)} | ||
*/ | ||
public RandomScoreFunctionBuilder seed(long seed) { | ||
this.seed = seed; | ||
return this; | ||
} | ||
|
||
/** | ||
* seed variant taking a long value. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this javadoc is wrong There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
* @see {@link #seed(int)} | ||
*/ | ||
public RandomScoreFunctionBuilder seed(String seed) { | ||
this.seed = seed; | ||
return this; | ||
} | ||
|
||
@Override | ||
public void doXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(getName()); | ||
if (seed != null) { | ||
builder.field("seed", seed.intValue()); | ||
if (seed instanceof Integer) { | ||
builder.field("seed", ((Integer)seed).intValue()); | ||
} else if (seed instanceof Long) { | ||
builder.field("seed", ((Long)seed).longValue()); | ||
} else if (seed instanceof String) { | ||
builder.field("seed", (String)seed); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should just do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to satisfy the possibility for a session id (say alphanum + dashes). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I modified the comment after you replied ^^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rjernst can you fix this ^^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, sorry, I misunderstood. Fixed. |
||
} | ||
builder.endObject(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can just make this
Number
and we try to parse the string?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nevermind I saw the usage