-
Notifications
You must be signed in to change notification settings - Fork 7
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
Update Java client to Search API v3 #30
Conversation
Hi @xSAVIKx This is not a proper review from me, I just have some questions. @roback will review, hopefully later this week.
Care to elaborate on this? Do you know the reason to as it sigfaults (did you mean "segfault"?)? Does the old version have the same problem with openjdk7? Do we really need a Thanks! |
README.md
Outdated
5. Run `gradlew uploadArchives -Prelease` to release to the staging repository | ||
6. Log into [Nexus Repository Manager](https://oss.sonatype.org/) and find the archive | ||
7. Read [Releasing the Deployment](http://central.sonatype.org/pages/releasing-the-deployment.html) | ||
8. Release to Central Repository using [Nexus Repository Manager](https://oss.sonatype.org/) |
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.
Actually, when rendered, Markdown will do the numbering, not having the order in the Markdown source makes for easier "refactoring", so we would like to keep it like that. :-)
From https://guides.github.com/features/mastering-markdown/
Source:
1. Item 1
1. Item 2
1. Item 3
1. Item 3a
1. Item 3b
Rendered:
- Item 1
- Item 2
- Item 3
- Item 3a
- Item 3b
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.
Yeah, but I mostly read raw markdown, that's why I'm always trying to use correct numbering.
If you do think it should be reverted to serie of 1.
- I'd do that.
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.
Yes, please revert to 1.
s
@dentarg Yes, misprint - segfault. As for the |
Yes, please cleanup |
reverted back Query and QueryBuilder classes and introduced deprecations for old stuff updated tests and examples
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.
Noticed some minor things, but I didn't have time to look everything over. I'll continue in the beginning of next week.
Did a few requests and that worked just fine 👍 (for the requests I did a least :P).
README.md
Outdated
// Create Query object using QueryBuilder for results in English published from startTime to endTime | ||
Query query = QueryBuilder.create("spotify").documentLanguage(Language.English).startTime(startTime).endTime(endTime).build(); | ||
Result result = client.makeRequest(query); | ||
Query q = "spotify"; |
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.
I think it's supposed to be String q
here :)
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.
Yeah :-) Or realy Query
object.
public String toStringRepresentation() { | ||
StringBuilder result = new StringBuilder(searchQuery); | ||
if (lang != null) { | ||
result.append(" lang: ").append(lang); |
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.
You can remove the space after the colon lang: en
should be lang:en
. (same for start/end-date below)
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.
OK
@@ -12,7 +12,12 @@ | |||
/** | |||
* The constant DATE_FORMAT. | |||
*/ | |||
public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; | |||
public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssX"; |
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.
X
-> Z
?
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.
@roback nope.
Z
in Java is for RFC standard only. And X
is for ISO standard.
public String toStringRepresentation() { | ||
StringBuilder result = new StringBuilder(searchQuery); | ||
if (lang != null) { | ||
result.append(" lang: ").append(lang); |
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.
You can remove the space after the colon. (lang: en
-> lang:en
)
* @return language | ||
* @since 3.0.0 | ||
*/ | ||
public String getLang() { |
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.
There is no need for getLang
and setLang
. It's enough with deprecating get/setDocumentLanguage
(as you have already done below).
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.
Ignore my comment :) You can go ahead with get/setLang
. I got a bit confused as the Java client uses a query builder which none of the other clients does.
* @return the location | ||
* @since 3.0.0 | ||
*/ | ||
public String getLocation() { |
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.
Remove get/setLocation
(they aren't used anywhere). Location is part of the query string.
Edit: Changed my mind :) We should keep this, but the location should be added to the query string in toStringRepresentation()
. A test that checks that the location gets added to the query string should be added as well.
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.
A test that checks that the location gets added to the query string should be added as well.
Not just a test for location, but a test that all attributes gets added to the query correctly.
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.
@roback done.
added additional test to ensure query string representation is OK removed additional date format - all dates now use same format
@@ -15,10 +15,6 @@ | |||
public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssX"; | |||
|
|||
/** | |||
* The constant DATE_FORMAT. | |||
*/ | |||
public static final String SEARCH_QUERY_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; |
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.
Great! Thanks for taking the time to update this as well :)
Hi @roback, how it is going? |
Unfortunately we have a few other things that has higher priority that we need to finish first, so I won't be able to continue with this at the moment. Sorry for keeping you waiting. |
query.setStartTime(lastPost.getPublished()); | ||
Result newResult = client.makeRequest(query); | ||
Date lastPublishedAt = lastPost.getPublishedAt(); | ||
q = q.toBuilder().startTime(lastPublishedAt).build(); |
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.
The type of q
can be changed into a QueryBuilder
instead of just a Query
. Then there is no need to call toBuilder()
.
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.
Here we can use QueryBuilder
, but we will have to call build()
anyway.
Result newResult = client.makeRequest(query); | ||
Date lastPublishedAt = lastPost.getPublishedAt(); | ||
q = q.toBuilder().startTime(lastPublishedAt).build(); | ||
Result newResult = client.makeRequest(q); |
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.
If a public Result makeRequest(QueryBuilder queryBuilder)
method was added to the client you wouldn't have to call .build()
here either.
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.
@roback It's actually not the best idea to allow passing QueryBuilder
into the client.
The reason for the Query
object existence is that it is immutable. While QueryBuilder
is mutable and we should try not to pass mutable data to the client (as mutability could lead to unpredictable side effects, i.e. someone will change QueryBuilder
state while client is still in process of query execution).
I'd prefer to leave it as is. If you do insist - I'll change the implementation.
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.
👍 Now that I know there is a reason for this we can leave it as is :)
* | ||
* @return the coordinates | ||
*/ | ||
public String getCoordinates() { |
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.
Posts containing coordinates doesn't work, it looks like it's always an empty string.
In the XML the coordinates looks like:
<coordinates>
<latitude>49.1</latitude>
<longitude>10.75</longitude>
</coordinates>
An example query for a post containing coordinates: https://api.twingly.com/blog/search/api/v3/search?apikey=KEY&q=id:7533026945919130930
In ruby we just put them in a hash: https://github.com/twingly/twingly-search-api-ruby/blob/dbf547f182d93137bb167eb99c9eda4a8197ac21/lib/twingly/search/parser.rb#L72-L75. I don't know what works best in Java though :)
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.
@roback There was just no info about how coordinates are represented.
I'll add mapping for coordinate a bit later.
Tested the coordinates and it worked great 👍 I will merge this now. |
I've updated the Java client to the latest v3 API.
What was done: