Skip to content

feat(java): browse objects/synonyms/rules #952

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

Merged
merged 3 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.algolia.utils;

import java.util.Iterator;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;

public class AlgoliaIterableHelper {

public static <T> Iterable<T> createIterable(Supplier<Iterator<T>> executeQuery, BooleanSupplier _hasNext) {
return new Iterable<T>() {
@Override
public Iterator<T> iterator() {
return new Iterator<T>() {
private boolean isFirstRequest = true;
private Iterator<T> currentIterator = null;

@Override
public boolean hasNext() {
if (isFirstRequest || (_hasNext.getAsBoolean() && !currentIterator.hasNext())) {
currentIterator = executeQuery.get();
isFirstRequest = false;
}
return currentIterator != null && currentIterator.hasNext();
}

@Override
public T next() {
if (currentIterator == null || !currentIterator.hasNext()) {
currentIterator = executeQuery.get();
isFirstRequest = false;
}
return currentIterator.next();
}
};
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.algolia.utils;

public class Holder<T> {

public T value;

public Holder() {
this.value = null;
}

public Holder(T value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static void main(String[] args) {
SearchResponses<Actor> sr = result.get();
Actor a = sr.getResults().get(0).getHits().get(0);
System.out.println(a.name);

} catch (InterruptedException e) {
System.err.println("InterrupedException" + e.getMessage());
e.printStackTrace();
Expand Down
11 changes: 0 additions & 11 deletions specs/search/paths/synonyms/common/schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@ synonymHit:
items:
type: string
description: List of query words that will match the token.
_highlightResult:
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't it still be there but a string?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm afraid in some case it can be the object, as defined here and in that case it would be a mess.
I'm not sure what's best

Copy link
Member

Choose a reason for hiding this comment

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

Maybe worth to go with what we know for now and assume that it can be an enum "synonym" or a free form object?

It should be enough until we have a proper use case to investigate, wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

Would it still be valid once the Java unknown parameter validation is removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FAIL_ON_UNKNOWN_PROPERTIES is already disabled for the client, but it will still fail when trying to deserialize a known property, maybe I could return null instead of throwing but then it's misleading.
Are you sure this property is ever used for synonym ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

for rules we have the same issue, it's listed in the doc but not in our spec

Copy link
Member

@shortcuts shortcuts Aug 25, 2022

Choose a reason for hiding this comment

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

In the JS client, browseRules and browseSynonyms both delete the _highlightResult key for each responses, but not in the searchRules and searchSynonyms methods. I'd be fine keeping the same logic until we have some context

maybe @Haroenv (off) @francoischalifour (?) knows more about those?

Copy link
Member

Choose a reason for hiding this comment

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

I don't know, but I would guess that we prefer having consistent keys when using search endpoints to facilitate the data flow in the consumers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

from usage it seems like _highlightResult is pretty random (example) so we remove it for now

type: object
description: Highlighted results.
additionalProperties: false
properties:
type:
$ref: '../../../common/schemas/Hit.yml#/highlightResultMap'
synonyms:
type: array
items:
$ref: '../../../common/schemas/Hit.yml#/highlightResultMap'
required:
- objectID
- type
Expand Down
4 changes: 2 additions & 2 deletions specs/search/paths/synonyms/searchSynonyms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ post:
description: Search or browse all synonyms, optionally filtering them by type.
parameters:
- $ref: '../../../common/parameters.yml#/IndexName'
- $ref: 'common/parameters.yml#/Type'
- $ref: './common/parameters.yml#/Type'
- $ref: '../../../common/parameters.yml#/PageDefault0'
- $ref: '../../../common/parameters.yml#/HitsPerPage'
requestBody:
Expand All @@ -28,7 +28,7 @@ post:
content:
application/json:
schema:
$ref: 'common/schemas.yml#/searchSynonymsResponse'
$ref: './common/schemas.yml#/searchSynonymsResponse'
'400':
$ref: '../../../common/responses/BadRequest.yml'
'402':
Expand Down
244 changes: 9 additions & 235 deletions templates/java/api.mustache

Large diffs are not rendered by default.

Loading