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

Update Java client to Search API v3 #30

Merged
merged 20 commits into from
May 30, 2017
Merged

Update Java client to Search API v3 #30

merged 20 commits into from
May 30, 2017

Conversation

xSAVIKx
Copy link
Contributor

@xSAVIKx xSAVIKx commented May 12, 2017

I've updated the Java client to the latest v3 API.

What was done:

  • dependencies versions were bumped to the latest ones
  • gradle version was bumped to the latest one
  • added .gitattribute in order to be sure that files have correct line endings on commits
  • updated the overall client classes to work with v3 API - can close Update Java client to Search API v3 [$50] #29.
  • added support for compression - can close HTTP compression #28.

@dentarg
Copy link
Contributor

dentarg commented May 15, 2017

Hi @xSAVIKx

This is not a proper review from me, I just have some questions. @roback will review, hopefully later this week.

disable openJDK build as it fails with sigfaults

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 .gitattributes that long for this repo?

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/)
Copy link
Contributor

@dentarg dentarg May 15, 2017

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:

  1. Item 1
  2. Item 2
  3. Item 3
    1. Item 3a
    2. Item 3b

Copy link
Contributor Author

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.

Copy link
Contributor

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

@xSAVIKx
Copy link
Contributor Author

xSAVIKx commented May 15, 2017

@dentarg Yes, misprint - segfault.
I do not know the reason and actually not willing to dig into the OpenJDK. It was introduced just as an option and I don't think anyone should invest time into making it work on Travis OpenJDK.

As for the .gitattributes - it's just a generated boilerplate for any possible project. If you do want - I can clean it up.

@dentarg
Copy link
Contributor

dentarg commented May 15, 2017

Yes, please cleanup .gitattributes

xSAVIKx added 2 commits May 16, 2017 20:10
reverted back Query and QueryBuilder classes and introduced deprecations for old stuff
updated tests and examples
@xSAVIKx
Copy link
Contributor Author

xSAVIKx commented May 18, 2017

@roback @dentarg Please review updates.

I've made client more backward-compatible - almost same changes as for the Python client.

Copy link
Member

@roback roback left a 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";
Copy link
Member

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 :)

Copy link
Contributor Author

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);
Copy link
Member

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)

Copy link
Contributor Author

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";
Copy link
Member

Choose a reason for hiding this comment

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

X -> Z?

Copy link
Contributor Author

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);
Copy link
Member

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() {
Copy link
Member

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).

Copy link
Member

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() {
Copy link
Member

@roback roback May 22, 2017

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@roback done.

xSAVIKx added 4 commits May 22, 2017 21:12
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";
Copy link
Member

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 :)

@yuri-sergiichuk
Copy link

Hi @roback, how it is going?

@roback
Copy link
Member

roback commented May 24, 2017

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();
Copy link
Member

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().

Copy link
Contributor Author

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);
Copy link
Member

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.

Copy link
Contributor Author

@xSAVIKx xSAVIKx May 29, 2017

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.

Copy link
Member

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() {
Copy link
Member

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 :)

Copy link
Contributor Author

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.

@roback
Copy link
Member

roback commented May 30, 2017

Tested the coordinates and it worked great 👍

I will merge this now.

@roback roback merged commit ad80047 into twingly:master May 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Java client to Search API v3 [$50] HTTP compression
4 participants