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

make SearchResult, Document and AggregationResult classes more developer friendly #121

Open
3 tasks
tgrall opened this issue Aug 14, 2020 · 0 comments
Open
3 tasks

Comments

@tgrall
Copy link
Contributor

tgrall commented Aug 14, 2020

  • SearchResult
  • Document
  • AggregationResult

We should improve the SearchResult and Document class more developer friendly, it could simply be a different serialization of the document.

Using proper name/value object/map, instead of a list of k/v.

Note: this is just capture as a possible improvement, more thinking is needed, but the idea would be to reduce the code when processing the result.

For example a SearchResult should be represented by a JSON class like this one:

{
   "totalResults":2,
   "docs":[
      {
         "meta":{
            "score":1,
            "id":"movie:1141"
         },
         "body":{
            "ibmdb_id":"tt0113277",
            "plot":"A group of professional ... heist.",
            "genre":"Drama",
            "release_year":"1995",
            "rating":"8.2",
            "votes":"560687",
            "title":"Heat",
            "poster":"https://m..._.jpg"
         }
      },
      {
         "meta":{
            "score":1,
            "id":"movie:818"
         },
         "body":{
            "ibmdb_id":"tt0112617",
            "plot":"A lifeguard bets he can be true to just one woman.",
            "genre":"Comedy",
            "release_year":"1995",
            "rating":"5.4",
            "votes":"32",
            "title":"California Heat",
            "poster":"N/A"
         }
      }
   ]
}

Instead of:

{
   "totalResults":2,
   "docs":[
      {
         "id":"movie:1141",
         "score":1,
         "payload":null,
         "properties":[
            {
               "ibmdb_id":"tt0113277"
            },
            {
               "plot":"A group of professional...heist."
            },
            {
               "genre":"Drama"
            },
            {
               "release_year":"1995"
            },
            {
               "rating":"8.2"
            },
            {
               "votes":"560687"
            },
            {
               "title":"Heat"
            },
            {
               "poster":"https://m.med..._.jpg"
            }
         ]
      },
      {
         "id":"movie:818",
         "score":1,
         "payload":null,
         "properties":[
            {
               "ibmdb_id":"tt0112617"
            },
            {
               "plot":"A lifeguard bets he can be true to just one woman."
            },
            {
               "genre":"Comedy"
            },
            {
               "release_year":"1995"
            },
            {
               "rating":"5.4"
            },
            {
               "votes":"32"
            },
            {
               "title":"California Heat"
            },
            {
               "poster":"N/A"
            }
         ]
      }
   ]
}

Possible solution:

        List<Map<String, Object>> docsToReturn = new ArrayList<>();
        List<Document> docs =  queryResult.docs;

        for (Document doc :docs) {

            Map<String,Object> props = new HashMap<>();
            Map<String,Object> meta = new HashMap<>();
            meta.put("id", doc.getId());
            meta.put("score", doc.getScore());
            doc.getProperties().forEach( e -> {
                props.put( e.getKey(), e.getValue() );
            });

            Map<String,Object> docMeta = new HashMap<>();
            docMeta.put("meta",meta);
            docMeta.put("body",props);
            docsToReturn.add(docMeta);
        }
@tgrall tgrall changed the title make SearchResult & Document classes more developer friendly make SearchResult, Document and AggregationResult classes more developer friendly Sep 17, 2020
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

No branches or pull requests

1 participant