Code Monkey home page Code Monkey logo

meilisearch-java's People

Contributors

alallema avatar amiralbl3ndic avatar ansavanix avatar axelrindle avatar bors[bot] avatar brunoocasali avatar curquiza avatar dennxa avatar dependabot-preview[bot] avatar dependabot[bot] avatar diegonavarroq avatar eskombro avatar ezienecker avatar irenejoeunpark avatar jd2024 avatar johandelvallev avatar jrhenderson1988 avatar junghoon-vans avatar kination avatar kuruvasatya avatar luis-valdez avatar mayralgr avatar meili-bors[bot] avatar meili-bot avatar mesutgk15 avatar nicolasvienot avatar niemannd avatar oraliahdz avatar theclerici avatar vishnugt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

meilisearch-java's Issues

Modify addDocument -> addDocuments method (to support multiple documents)

To add documents to MeiliSearch the API requires a JSON object composed of an array of documents, either if you are sending one or multiple documents in the same request. In this case we need a method called addDocuments taking a list of documents as a parameter. This method can handle a single document in the exact same way. It would probably be better to replace the addDocument method

Test placeholder search

Placeholder search lets the user send a null query parameter in order to apply all the ranking rules to the documents in the index without matching them with a specific query, and return the results to the user. It is different to sending an empty string as a query, in which case you won't receive any results. This behavior should be explicitly tested in the SDK.

More info about Placeholder search here


UPDATE:

Placeholder works 👍

Placeholder Search can be used by:

  • Using a null query: q=null
  • Using an empty String: q=""

Tests are still missing (both options, null and empty String, should be tested).

Managing parameter input

Currently, it needs to generate json -> string for POST:

Indexes book = ms.getIndex("books");
        
JsonArray jsonArray = new JsonArray();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("1111", "alice in wonderland");
jsonArray.add(jsonObject);

// add new document "[{"1111": "alice in wonderland"}]"
String response = book.addDocument(jsonObject.toString());

To make this simple:

  1. Accept JSON modules(Gson, Jackson, ...) as input
  2. Create custom input format(it will use JSON module internally to convert input into JSON format)

CreateIndex should return an Index instance

In the current implementation, getIndex() returns an Index instance, but createIndex() returns the response of the POST request for creating an index. This forces a usage that looks like this:

...
String i = ms.createIndex(indexUid);
Index index = ms.getIndex(indexUid);
index.addDocuments(...)
...

In case createIndex succeeds, it should return an Index instance which simplifies the usage to

...
Index index = ms.createIndex(indexUid);
index.addDocuments(...)
...

In case of error, this will be handled by #7

Add a CONTRIBUTING.md

Create a nice welcoming file for new contributors, specifying every detail, and especially the developer workflow, and how to test, lint and release (whenever we have tests and linters etc...).

It can be inspired in our SDKs CONTRIBUTING.md files, such as this or this

Improve SDK automated documentation [javadoc]

meilisearch-java uses javadoc as a documentation generator, which is based on comments on the code. There are several classes, methods, and attributes that are very useful for developers who use our SDK that have no comment, and therefore no automated documentation.

Several warnings are shown when your build includes the task javadoc. It would be interesting to add some documentation to the most important classes and methods, and to suppress the warnings of those who do not need to be documented.

This is a good first issue to understand the project, and how it is plugged to MeiliSearch

Note: This doesn't need to be solved all in one single PR, any partial contribution would be appreciated.


I would say that the most important is to add the appropriate comments to the main classes: Client, Index, Search, SearchRequest and it's main methods with a short description of the method, params, return values and Exceptions

As an example:

/**
 * Wait for a pending update to be processed
 *
 * @param updateId ID of the index update
 * @param timeoutInMs number of milliseconds before throwing an Exception
 * @param intervalInMs number of milliseconds before requesting the status again
 * @throws Exception if timeout is reached
 */
public void waitForPendingUpdate(int updateId, int timeoutInMs, int intervalInMs) throws Exception {
	// ...
}

Rename addDocument method to addDocuments

The HTTP API for indexing documents takes always a JSON array of documents as a parameter, either if you want to index a single document or a batch. In which case we should probably expose just a single method for both, and rename it in its plural way as addDocuments(...) :)

Implement settings methods

There are 3 main methods that are missing in this package. If I'm wrong, feel free to close this issue, but I don't find anything when I search for settings in this repository.

The updateSettings route should be able to work even if all the settings (rankingRules, distinctAttribute, synonyms...) are not all passed. A similar implementation to the SearchRequest class with all the setXXX methods for the Settings class could be useful: https://github.com/meilisearch/meilisearch-java/blob/2b042ada803cd207730b85db4e10157a9ed3d923/src/main/java/com/meilisearch/sdk/SearchRequest.java.

Steps:

  • Add the Settings class with all the needed methods
  • Add the 3 settings methods (get, update, reset)
  • Add tests

Feel free to ask any question if something is not clear to you 🙂

Add facetsDistribution in SearchRequest

Description
Add facetsDistribution as query parameter in SearchRequest.

Basic example

SearchRequest searchRequest = new SearchRequest("knight")
	.setFacetsDistribution(new String[]{"*"});
new SearchRequest("prince", 200, 900, new String[]{"bubble"}, new String[]{"crop"}, 900, new String[]{"highlight"}, "tag='romance'", true, new String[]{"title"});

Implement ServiceTemplates on SDK

#92 Introduces the ServiceTemplate, which makes the API implementation independent from the HTTP Client and JSON handler. This level of abstraction is not yet used by the SDK and will probably introduce breaking changes.

Document this implementation

Create and fill sample file to display Java examples in MeiliSearch Documentation

Code Samples for MeiliSearch documentation

Introduction

As MeiliSearch grows so does its SDK's. More and more SDK's rises from the ground and they all deserve to be as well documented as the core engine itself.

The most common way for a user to understand MeiliSearch is to go to its official documentation. As of yesterday all examples in the documentation were made with cURL. Unfortunately, most of our users do not communicate with MeiliSearch directly with cURL. Which forces them to search for the specific references somewhere else (in the readme's, in the sdk's code itself,..). This makes for unnecessary friction.

Goal

We want our documentation to include all SDK's

As a first step we want all examples to be made using the most possible SDK's. As did Stripe and Algolia.

sdk_sample

examples with curl, javascript and soon enough this SDK too!

To achieve this it is expected from this SDK to create a sample file containing all the code samples needed by the documentation.

These are the steps to follow:

  • Create your sample file
  • Fill your sample file
  • Add your samples to the documentation

Create your sample file

The sample file is a yaml file added at the root of each MeiliSearch SDK.
Sample files are created based on the sample-template.yaml file.

sample-template file:

get_one_index_1: |-
list_all_indexes_1: |-
create_an_index_1: |-
...

This template is accessible publicly here or in the public directory : .vuepress/public/sample-template.yaml of the documentation.

The name of the file should be .code-samples.meilisearch.yaml

Fill your sample file

After creating the sample file with the content of the sample template you should have a file containing all the sampleId's.

get_one_index_1: |-
list_all_indexes_1: |-
create_an_index_1: |-
...

By the name of the different sampleId you should know where that code sample will be added to the documentation.

For example, create_an_index_1 is the first example in the API References of the index creation.

Using the already existing cURL example in the documentation you should see what is expected from that sample. It is very important that you look at the already existing samples in the documentation as it gives you the parameters to use in your sample to match with the rest of the documentation.

Good sample based on documentation:

create_an_index_1: |-
  client.createIndex({ uid: 'movies' })

Bad sample that does not match with the response.

create_an_index_1: |-
  client.createIndex({ uid: 'otherName' })

Each sample is expected to be written in the respective SDK language.

Javascript example:

get_one_index_1: |-
  client.getIndex('movies').show()
list_all_indexes_1: |-
  client.listIndexes()
create_an_index_1: |-
  client.createIndex({ uid: 'movies' })
  ...

The complete cURL sample file is available at the root of the documentation repository.
Every other SDK sample file should be available at the root of their respective repository.

Formatting Exception

There is one exception to the formatting rule.
When the sampleId finishes with _md it means it is expected to be written in markdown format.

JavaScript sample id with _md extension:
yaml-js-example

Add your samples to the documentation

Once your sample file is filled with the code samples, you will need to create a pull request on the documentation repository.

Open the following file in your IDE:
.vuepress/code-samples/sdks.json

And add your sample file to the list:

[
  ...
  {
    "language": "sdk-language",
    "label": "sdk-label",
    "url": "url to yaml file"
  }
]

The language key expect a supported language for the code highlight.

The label key is the name of the tab. While label and language could have been the same, it created some conflict (i.e: bash and cURL).

The url is the raw link to access your sample file. It should look like this:
https://raw.githubusercontent.com/[PROJECT]/[REPO]/.code-samples.meilisearch.yaml

Choose a linter and integrate it to CI and docs

  • Choose a well maintained and known Linter for Java
  • Run the linter for the whole SDK code and make a Pull Request
  • Add a task in the CI [GitHub Actions] that runs automatically the linter (Lint will be required for any merge/contribution afterwards)

Do not hesitate to contact us if you have any doubts or questions!

Add a LICENSE

Include a copy if the MIT License in the root of the repo

Change the trigger in the publish workflow

Currently, the trigger for the publish workflow is based on the name of the tag on push.
We want to trigger the workflow on release, irrespective of the tag.

⚠️ Should be done by a MeiliSearch team member.

Create and fill sample file to display Java examples in MeiliSearch Documentation

Code Samples for MeiliSearch documentation

Introduction

As MeiliSearch grows so does its SDK's. More and more SDK's rises from the ground and they all deserve to be as well documented as the core engine itself.

The most common way for a user to understand MeiliSearch is to go to its official documentation. As of yesterday all examples in the documentation were made with cURL. Unfortunately, most of our users do not communicate with MeiliSearch directly with cURL. Which forces them to search for the specific references somewhere else (in the readme's, in the sdk's code itself,..). This makes for unnecessary friction.

Goal

We want our documentation to include all SDK's

As a first step we want all examples to be made using the most possible SDK's. As did Stripe and Algolia.

sdk_sample

examples with curl, javascript and soon enough this SDK too!

To achieve this it is expected from this SDK to create a sample file containing all the code samples needed by the documentation.

These are the steps to follow:

  • Create your sample file
  • Fill your sample file
  • Add your samples to the documentation

Create your sample file

The sample file is a yaml file added at the root of each MeiliSearch SDK.
Sample files are created based on the sample-template.yaml file.

sample-template file:

get_one_index_1: |-
list_all_indexes_1: |-
create_an_index_1: |-
...

This template is accessible publicly here or in the public directory : .vuepress/public/sample-template.yaml of the documentation.

The name of the file should be .code-samples.meilisearch.yaml

Fill your sample file

After creating the sample file with the content of the sample template you should have a file containing all the sampleId's.

get_one_index_1: |-
list_all_indexes_1: |-
create_an_index_1: |-
...

By the name of the different sampleId you should know where that code sample will be added to the documentation.

For example, create_an_index_1 is the first example in the API References of the index creation.

Using the already existing cURL example in the documentation you should see what is expected from that sample. It is very important that you look at the already existing samples in the documentation as it gives you the parameters to use in your sample to match with the rest of the documentation.

Good sample based on documentation:

create_an_index_1: |-
  client.createIndex({ uid: 'movies' })

Bad sample that does not match with the response.

create_an_index_1: |-
  client.createIndex({ uid: 'otherName' })

Each sample is expected to be written in the respective SDK language.

Javascript example:

get_one_index_1: |-
  client.getIndex('movies').show()
list_all_indexes_1: |-
  client.listIndexes()
create_an_index_1: |-
  client.createIndex({ uid: 'movies' })
  ...

The complete cURL sample file is available at the root of the documentation repository.
Every other SDK sample file should be available at the root of their respective repository.

Formatting Exception

There is one exception to the formatting rule.
When the sampleId finishes with _md it means it is expected to be written in markdown format.

JavaScript sample id with _md extension:
yaml-js-example

Add your samples to the documentation

Once your sample file is filled with the code samples, you will need to create a pull request on the documentation repository.

Open the following file in your IDE:
.vuepress/code-samples/sdks.json

And add your sample file to the list:

[
  ...
  {
    "language": "sdk-language",
    "label": "sdk-label",
    "url": "url to yaml file"
  }
]

The language key expect a supported language for the code highlight.

The label key is the name of the tab. While label and language could have been the same, it created some conflict (i.e: bash and cURL).

The url is the raw link to access your sample file. It should look like this:
https://raw.githubusercontent.com/[PROJECT]/[REPO]/.code-samples.meilisearch.yaml

Generic class for search results

In the current state of the Java SDK, the return value of the search method is a String, which needs to be deserialized by the user after performing a search.

This SDK should provide a generic class capable of deserializing MeiliSearch results. Search method should return an instance of this object, with MeiliSearch's results already deserialized.

Lacking genericity

The wrapper lacks genericity a lot: for the moment each data it returns is a string and must be parsed by the program using the wrapper.
We should implement generic methods allowing to retrieve dynamically mapped types rather than simply strings.

[Enconding UTF-8 BasicHttpRequest] Am I missing something with encoding ?

Hello,
I'm facing an issue here, i have meilisearch running in a docker container (last image)
I use meilisearch-java 0.2.0.

I have a doc.json encoded in UTF-8 that contains © and … "spécial" characters.
[{"id":1,"content":"© hop"},{"id":2,"content":"… hop"}]

The following command line is working perfectly as expected.

$ curl  -H "X-Meili-API-Key: masterKey" -X POST 'http://127.0.0.1:7700/indexes/kiki/documents'   --data @doc.json
{"updateId":0}

The following line using meilisearch-java is returning an error:
index.addDocuments("[{\"id\":1,\"content\":\"© hopaaa\"},{\"id\":2,\"content\":\"… hop\"}]")
Invalid JSON: invalid unicode code point at line 1 column 29

image

I have this problem with all the UTF8 html file i'm trying to index... and it's driving me a bit crazy.
What am i missing? Could this be a bug ?

Add errors to updateStatus Class

An update status contains, in case of failure, relevant information about the error (message, code and a link to the description of the error in the docs) that should be added to the UpdateStatus for further usage in this SDK and for users!

Example of a failed update:

{
"status":"failed",
"updateId":1,
"type": {
  "name":"DocumentsAddition",
  "number":2
},
"duration":2.55E-5,
"enqueuedAt":"2020-09-28T20:17:27.005486800Z",
"processedAt":"2020-09-28T20:17:27.016900700Z",
"errorCode":"missing_document_id",
"errorType":"invalid_request_error",
"errorLink":"https://docs.meilisearch.com/errors#missing_document_id"
}

Update README

  • Quickstart
  • API table
  • Installation guide
  • Description

Implement changes due to implicit index creation

Related to meilisearch/integration-guides#48

  • Change the Getting Started as described in the main issue.
  • get_index() does an HTTP call and is not the main method to use anymore.
  • Add the index() method
  • Add tests for index() method
  • Update get_or_create_index with the new way of using index()
  • Add a fetchPrimaryKey() method to Index class. The attribute primaryKey is not updated when using the index() method: the method does not do any HTTP call. Refer to the limitation section in the main issue.

Implement a method to delete a batch of documents

The implementation for this route letting the user delete a batch of documents by providing a list of document ids is missing from the SDK.

Method names should be explicit, for making the difference obvious, like deleteAllDocuments() and deleteDocuments([...]) (these are the method names used in other MeiliSearch SDKs)

  • Implement the method for deleting a batch of documents as deleteDocuments([...])
  • Rename the deleteDocuments method (which currently deletes all documents) to deleteAllDocuments()
  • Add tests for deleteDocuments()

Add a check-release script

Currently, there is no check that the version of the package that will be published match the release tag.
We want to implement the check when the publish workflow is triggered (ossrh-publish.yml)

⚠️ Should be done by a MeiliSearch team member.

Document the customizations

If I understand well, this library provides default usage but also provides abstractions to choose and customize:

  • the JSON library
  • the Client
  • the HTTP requests

It would be nice to add a section in the README to show with simple lines of code how to customize all of these points 🙂

Create Javadoc and Sources

Due to the changes made to the build.gradle (updating to maven-publish), the build and publish tasks don't create the javadoc and sources anymore.

This is needed by the Central Repository to publish a package.

Add documentation on Search

Inspired on our PHP SDK's search wiki, this document can specify features about search as the different methods exposed to the user (search() and rawSearch(), different constructors for this methods etc...

The repo's README can have a link to this WIKI in the Custom Search section as in this PHP README example

updateIndex method should return an Index instance

To be consistent with createIndex and getIndex, the method updateIndex should return an Index instance. This method should update the primaryKey attribute of the Index instance with the information returned by MeiliSearch.

  • Update the code base
  • Add tests

EDIT: this PR (#74) should have been merged before.

Change master branch to main

Let's be allies and make this change that means a lot.

Here is a blog post that explain a little more why it's important, and how to easily do it. It will be a bit more complicated with automation, but we still should do it!

A better way to add documents in the Getting Started example?

Currently, here is the way to add documents we show in the first Getting Started example:

final String documents = "["
	+ "{\"book_id\": 123, \"title\": \"Pride and Prejudice\"},"
	+ "{\"book_id\": 456, \"title\": \"Le Petit Prince\"},"
	+ "{\"book_id\": 1, \"title\": \"Alice In Wonderland\"},"
	+ "{\"book_id\": 1344, \"title\": \"The Hobbit\"},"
	+ "{\"book_id\": 4, \"title\": \"Harry Potter and the Half-Blood Prince\"},"
	+ "{\"book_id\": 2, \"title\": \"The Hitchhiker\'s Guide to the Galaxy\"}"
	+ "]";

We would like to use, if it exists, a more friendly way to add documents that we can introduce into our Getting Started, instead of escaping double-quotes.

Maybe we could be inspired by the Stripe Java client and the HashMap solution, but it might also involve lots of lines, and this solution might be "heavy" too.
https://github.com/stripe/stripe-java#usage

What do you think?
Does someone know a way to make the Getting Started example more friendly? 😄

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.