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

feat(search): add search endpoint for API #299

Open
wants to merge 11 commits into
base: master
from

Conversation

@akhilesh26
Copy link
Contributor

commented Aug 16, 2019

No description provided.

@coveralls

This comment has been minimized.

Copy link

commented Aug 16, 2019

Coverage Status

Coverage increased (+1.6%) to 44.684% when pulling b3c024f on akhilesh26:search_api into bdf0bb4 on bookbrainz:master.

akhilesh26 added 2 commits Aug 18, 2019
refactor: remove redundant code of search helper.
move search helper from /server/helpers to /common/helpers and update the accordingly.
@akhilesh26

This comment has been minimized.

Copy link
Contributor Author

commented Aug 18, 2019

Hi @MonkeyDo,
When the search request goes from the test-search.js, the result does not come from elasticsearch properly that's why tests are failing. When the same request goes from Postman, the proper response is coming. I tried to find the issue but unable to reach. Please help to resolve this.
my test.json is here

@akhilesh26

This comment has been minimized.

Copy link
Contributor Author

commented Aug 22, 2019

Hi @MonkeyDo,
Please review this also, when you have time. Let me know if any changes will be required.

@MonkeyDo

This comment has been minimized.

Copy link
Contributor

commented Aug 24, 2019

I've done a bit of reading, and come to the conclusion the easiest way to set up the tests is to mimic ElasticSearch without running any real instance.
You can use the nock package to intercept calls to ElasticSearch (using the values defined in the test.json config file as it is done here ) and return a fake response that mimics ElasticSearch.

Here is what a usual ES response looks like:

@MonkeyDo
Copy link
Contributor

left a comment

I've done a bit of reading regarding how to test this best, and come to the conclusion the easiest way to set it up is to mimic ElasticSearch without running any real instance.
You can use the nock package to intercept calls to ElasticSearch (using the values defined in the test.json config file as it is done here ) and return a fake response that mimics ElasticSearch.

To get an example of an ES response, you can put an inline breakpoint in VSCode (right-click > "Add inline breakpoint") here to intercept a response from ES, then in the debug console run JSON.stringify(searchResponse).
With that and a bit of perseverance, I think you can set up a fake ES response that will satisfy the tests.

Here is what that searchResponse looks like when running both search tests.
For the first test:

{
    "took": 111,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 98,
        "max_score": 33.945618,
        "hits": [
            {
                "_index": "bookbrainz",
                "_type": "author",
                "_id": "9f54506d-09e6-4856-8818-eecb03b071db",
                "_score": 33.945618,
                "_source": {
                    "bbid": "9f54506d-09e6-4856-8818-eecb03b071db",
                    "dataId": 3205,
                    "revisionId": 9923,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 8629,
                    "beginYear": 1997,
                    "beginMonth": 9,
                    "beginDay": 6,
                    "beginAreaId": null,
                    "endYear": null,
                    "endMonth": null,
                    "endDay": null,
                    "endAreaId": null,
                    "ended": false,
                    "areaId": null,
                    "genderId": 1,
                    "typeId": 1,
                    "aliasSetId": 7590,
                    "identifierSetId": 2512,
                    "relationshipSetId": null,
                    "type": "Author",
                    "defaultAlias": {
                        "id": 8629,
                        "name": "Harry Drizzy",
                        "sortName": "Drizzy, Harry",
                        "languageId": 284,
                        "primary": true
                    },
                    "gender": {
                        "id": 1,
                        "name": "Male",
                        "parent": null,
                        "childOrder": 1,
                        "description": null
                    },
                    "authorType": {
                        "id": 1,
                        "label": "Person"
                    },
                    "beginDate": "+001997-09-06",
                    "endDate": null
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "edition",
                "_id": "22e4c608-1b01-4f0e-b10d-6f406b625860",
                "_score": 33.446167,
                "_source": {
                    "bbid": "22e4c608-1b01-4f0e-b10d-6f406b625860",
                    "dataId": 773,
                    "revisionId": 4378,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 3272,
                    "editionGroupBbid": "360ebc31-3961-43bb-b533-ed2a7882231b",
                    "authorCreditId": null,
                    "width": null,
                    "height": null,
                    "depth": null,
                    "weight": null,
                    "pages": null,
                    "formatId": null,
                    "statusId": 1,
                    "aliasSetId": 2855,
                    "identifierSetId": null,
                    "relationshipSetId": null,
                    "type": "Edition",
                    "languageSetId": null,
                    "releaseEventSetId": null,
                    "publisherSetId": 537,
                    "defaultAlias": {
                        "id": 3272,
                        "name": "Harry Potter",
                        "sortName": "Potter, Harry",
                        "languageId": 284,
                        "primary": true
                    },
                    "editionStatus": {
                        "id": 1,
                        "label": "Official"
                    },
                    "editionGroup": {
                        "bbid": "360ebc31-3961-43bb-b533-ed2a7882231b",
                        "dataId": 31,
                        "revisionId": 1616,
                        "master": true,
                        "annotationId": null,
                        "disambiguationId": null,
                        "defaultAliasId": 4,
                        "typeId": 1,
                        "aliasSetId": 37,
                        "identifierSetId": null,
                        "relationshipSetId": 18,
                        "type": "EditionGroup"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "edition",
                "_id": "96a23368-85a1-4559-b3df-16833893d861",
                "_score": 33.446167,
                "_source": {
                    "bbid": "96a23368-85a1-4559-b3df-16833893d861",
                    "dataId": 1105,
                    "revisionId": 6126,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 5057,
                    "editionGroupBbid": "eaa480fa-3f95-4373-ade7-467aad674d58",
                    "authorCreditId": null,
                    "width": null,
                    "height": null,
                    "depth": null,
                    "weight": null,
                    "pages": null,
                    "formatId": null,
                    "statusId": null,
                    "aliasSetId": 4503,
                    "identifierSetId": null,
                    "relationshipSetId": null,
                    "type": "Edition",
                    "languageSetId": null,
                    "releaseEventSetId": null,
                    "publisherSetId": null,
                    "defaultAlias": {
                        "id": 5057,
                        "name": "Harry Potter",
                        "sortName": "Potter, Harry",
                        "languageId": 120,
                        "primary": true
                    },
                    "editionGroup": {
                        "bbid": "eaa480fa-3f95-4373-ade7-467aad674d58",
                        "dataId": 42,
                        "revisionId": 19,
                        "master": true,
                        "annotationId": null,
                        "disambiguationId": null,
                        "defaultAliasId": 10,
                        "typeId": 1,
                        "aliasSetId": 44,
                        "identifierSetId": null,
                        "relationshipSetId": 25,
                        "type": "EditionGroup"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "work",
                "_id": "ba446064-90a5-447b-abe5-139be547da2e",
                "_score": 31.27786,
                "_source": {
                    "bbid": "ba446064-90a5-447b-abe5-139be547da2e",
                    "dataId": 2811,
                    "revisionId": 8892,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 3466,
                    "typeId": 3,
                    "aliasSetId": 3039,
                    "identifierSetId": null,
                    "relationshipSetId": 2847,
                    "type": "Work",
                    "languageSetId": 1857,
                    "defaultAlias": {
                        "id": 3466,
                        "name": "Harry Potter",
                        "sortName": "Harry Potter",
                        "languageId": 120,
                        "primary": true
                    },
                    "workType": {
                        "id": 3,
                        "label": "Epic"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "author",
                "_id": "e6479e3e-ba78-4138-a778-e1067bbe4e4b",
                "_score": 26.634445,
                "_source": {
                    "bbid": "e6479e3e-ba78-4138-a778-e1067bbe4e4b",
                    "dataId": 660,
                    "revisionId": 1754,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 1139,
                    "beginYear": 1934,
                    "beginMonth": 3,
                    "beginDay": 13,
                    "beginAreaId": null,
                    "endYear": null,
                    "endMonth": null,
                    "endDay": null,
                    "endAreaId": null,
                    "ended": false,
                    "areaId": null,
                    "genderId": 1,
                    "typeId": 1,
                    "aliasSetId": 1114,
                    "identifierSetId": 1184,
                    "relationshipSetId": 1149,
                    "type": "Author",
                    "defaultAlias": {
                        "id": 1139,
                        "name": "Barry Hughart",
                        "sortName": "Hughart, Barry",
                        "languageId": null,
                        "primary": true
                    },
                    "gender": {
                        "id": 1,
                        "name": "Male",
                        "parent": null,
                        "childOrder": 1,
                        "description": null
                    },
                    "authorType": {
                        "id": 1,
                        "label": "Person"
                    },
                    "beginDate": "+001934-03-13",
                    "endDate": null
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "edition",
                "_id": "15208233-e7ff-44d9-95f0-f8b2b2d21a33",
                "_score": 23.375862,
                "_source": {
                    "bbid": "15208233-e7ff-44d9-95f0-f8b2b2d21a33",
                    "dataId": 1022,
                    "revisionId": 5744,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 4682,
                    "editionGroupBbid": "eaa480fa-3f95-4373-ade7-467aad674d58",
                    "authorCreditId": null,
                    "width": null,
                    "height": null,
                    "depth": null,
                    "weight": null,
                    "pages": null,
                    "formatId": 2,
                    "statusId": 1,
                    "aliasSetId": 4140,
                    "identifierSetId": null,
                    "relationshipSetId": null,
                    "type": "Edition",
                    "languageSetId": 2488,
                    "releaseEventSetId": 830,
                    "publisherSetId": 705,
                    "editionFormat": {
                        "id": 2,
                        "label": "Hardcover"
                    },
                    "defaultAlias": {
                        "id": 4682,
                        "name": "Harry Potter and the Half-Blood Prince",
                        "sortName": "Prince, Harry Potter and the Half-Blood",
                        "languageId": 120,
                        "primary": true
                    },
                    "editionStatus": {
                        "id": 1,
                        "label": "Official"
                    },
                    "editionGroup": {
                        "bbid": "eaa480fa-3f95-4373-ade7-467aad674d58",
                        "dataId": 42,
                        "revisionId": 19,
                        "master": true,
                        "annotationId": null,
                        "disambiguationId": null,
                        "defaultAliasId": 10,
                        "typeId": 1,
                        "aliasSetId": 44,
                        "identifierSetId": null,
                        "relationshipSetId": 25,
                        "type": "EditionGroup"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "edition_group",
                "_id": "9f49df73-8ee5-4c5f-8803-427c9b216d8f",
                "_score": 23.070309,
                "_source": {
                    "bbid": "9f49df73-8ee5-4c5f-8803-427c9b216d8f",
                    "dataId": 44,
                    "revisionId": 20,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 11,
                    "typeId": 1,
                    "aliasSetId": 45,
                    "identifierSetId": null,
                    "relationshipSetId": 26,
                    "type": "EditionGroup",
                    "defaultAlias": {
                        "id": 11,
                        "name": "Harry Potter and the Deathly Hallows",
                        "sortName": "Harry Potter and the Deathly Hallows",
                        "languageId": 120,
                        "primary": true
                    },
                    "editionGroupType": {
                        "id": 1,
                        "label": "Book"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "edition_group",
                "_id": "6b3a18ad-08fd-4d2d-9ab5-a906579950f7",
                "_score": 23.070309,
                "_source": {
                    "bbid": "6b3a18ad-08fd-4d2d-9ab5-a906579950f7",
                    "dataId": 1156,
                    "revisionId": 7576,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 6525,
                    "typeId": 1,
                    "aliasSetId": 5917,
                    "identifierSetId": 1951,
                    "relationshipSetId": null,
                    "type": "EditionGroup",
                    "defaultAlias": {
                        "id": 6525,
                        "name": "Harry Potter and the Deathly Hallows",
                        "sortName": "Deathly Hallows, Harry Potter",
                        "languageId": 284,
                        "primary": true
                    },
                    "editionGroupType": {
                        "id": 1,
                        "label": "Book"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "edition_group",
                "_id": "26c7b40c-247d-4352-93be-e6faf66f8f13",
                "_score": 22.852316,
                "_source": {
                    "bbid": "26c7b40c-247d-4352-93be-e6faf66f8f13",
                    "dataId": 1110,
                    "revisionId": 7355,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 6298,
                    "typeId": 1,
                    "aliasSetId": 5696,
                    "identifierSetId": null,
                    "relationshipSetId": null,
                    "type": "EditionGroup",
                    "defaultAlias": {
                        "id": 6298,
                        "name": "Harry Potter and The Deathly Hallows",
                        "sortName": "Hallows, Harry Potter and The Deathly",
                        "languageId": 16,
                        "primary": true
                    },
                    "editionGroupType": {
                        "id": 1,
                        "label": "Book"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "edition",
                "_id": "ceb76296-45a4-44fe-a1da-8ae6ff341f96",
                "_score": 22.847486,
                "_source": {
                    "bbid": "ceb76296-45a4-44fe-a1da-8ae6ff341f96",
                    "dataId": 1361,
                    "revisionId": 7356,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 6299,
                    "editionGroupBbid": "26c7b40c-247d-4352-93be-e6faf66f8f13",
                    "authorCreditId": null,
                    "width": null,
                    "height": null,
                    "depth": null,
                    "weight": null,
                    "pages": null,
                    "formatId": null,
                    "statusId": null,
                    "aliasSetId": 5697,
                    "identifierSetId": null,
                    "relationshipSetId": null,
                    "type": "Edition",
                    "languageSetId": null,
                    "releaseEventSetId": null,
                    "publisherSetId": null,
                    "defaultAlias": {
                        "id": 6299,
                        "name": "Harry Potter and the Deathly Hallows",
                        "sortName": "Hallows, Harry Potter and the Deathly",
                        "languageId": 120,
                        "primary": true
                    },
                    "editionGroup": {
                        "bbid": "26c7b40c-247d-4352-93be-e6faf66f8f13",
                        "dataId": 1110,
                        "revisionId": 7355,
                        "master": true,
                        "annotationId": null,
                        "disambiguationId": null,
                        "defaultAliasId": 6298,
                        "typeId": 1,
                        "aliasSetId": 5696,
                        "identifierSetId": null,
                        "relationshipSetId": null,
                        "type": "EditionGroup"
                    }
                }
            }
        ]
    }
}

And for the second test with collection query param:

{
    "took": 119,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 31,
        "max_score": 31.27786,
        "hits": [
            {
                "_index": "bookbrainz",
                "_type": "work",
                "_id": "ba446064-90a5-447b-abe5-139be547da2e",
                "_score": 31.27786,
                "_source": {
                    "bbid": "ba446064-90a5-447b-abe5-139be547da2e",
                    "dataId": 2811,
                    "revisionId": 8892,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 3466,
                    "typeId": 3,
                    "aliasSetId": 3039,
                    "identifierSetId": null,
                    "relationshipSetId": 2847,
                    "type": "Work",
                    "languageSetId": 1857,
                    "defaultAlias": {
                        "id": 3466,
                        "name": "Harry Potter",
                        "sortName": "Harry Potter",
                        "languageId": 120,
                        "primary": true
                    },
                    "workType": {
                        "id": 3,
                        "label": "Epic"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "work",
                "_id": "e9fad773-4b60-4c25-b6d2-c3a90ea31f89",
                "_score": 22.545055,
                "_source": {
                    "bbid": "e9fad773-4b60-4c25-b6d2-c3a90ea31f89",
                    "dataId": 2812,
                    "revisionId": 8893,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 6630,
                    "typeId": 1,
                    "aliasSetId": 6020,
                    "identifierSetId": null,
                    "relationshipSetId": 2848,
                    "type": "Work",
                    "languageSetId": 3581,
                    "defaultAlias": {
                        "id": 6630,
                        "name": "Harry Potter and the Half-Blood Prince",
                        "sortName": "Half-Blood Prince, Harry Potter",
                        "languageId": 120,
                        "primary": true
                    },
                    "workType": {
                        "id": 1,
                        "label": "Novel"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "work",
                "_id": "ca48b9c9-2b57-499f-8f74-b27e24578798",
                "_score": 21.703905,
                "_source": {
                    "bbid": "ca48b9c9-2b57-499f-8f74-b27e24578798",
                    "dataId": 2254,
                    "revisionId": 7178,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": 264,
                    "defaultAliasId": 6122,
                    "typeId": 1,
                    "aliasSetId": 5521,
                    "identifierSetId": null,
                    "relationshipSetId": null,
                    "type": "Work",
                    "languageSetId": 3332,
                    "disambiguation": {
                        "id": 264,
                        "comment": "Harry Potter series"
                    },
                    "defaultAlias": {
                        "id": 6122,
                        "name": "Harry Potter and the Cursed Child",
                        "sortName": "Harry Potter and the Cursed Child",
                        "languageId": 120,
                        "primary": true
                    },
                    "workType": {
                        "id": 1,
                        "label": "Novel"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "work",
                "_id": "7f9c7bbd-38b1-477b-ab19-3e1c16f7f0c0",
                "_score": 21.56199,
                "_source": {
                    "bbid": "7f9c7bbd-38b1-477b-ab19-3e1c16f7f0c0",
                    "dataId": 1808,
                    "revisionId": 5609,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 4561,
                    "typeId": 1,
                    "aliasSetId": 4024,
                    "identifierSetId": null,
                    "relationshipSetId": null,
                    "type": "Work",
                    "languageSetId": 2425,
                    "defaultAlias": {
                        "id": 4561,
                        "name": "Harry Potter and the Goblet of Fire",
                        "sortName": "Harry Potter and the Goblet of Fire",
                        "languageId": 284,
                        "primary": true
                    },
                    "workType": {
                        "id": 1,
                        "label": "Novel"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "work",
                "_id": "0460018a-ad33-4b95-9951-1cce1a9a441b",
                "_score": 21.49533,
                "_source": {
                    "bbid": "0460018a-ad33-4b95-9951-1cce1a9a441b",
                    "dataId": 2386,
                    "revisionId": 7682,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 6631,
                    "typeId": 1,
                    "aliasSetId": 6021,
                    "identifierSetId": 1952,
                    "relationshipSetId": null,
                    "type": "Work",
                    "languageSetId": 3582,
                    "defaultAlias": {
                        "id": 6631,
                        "name": "Harry Potter and the Deathly Hallows",
                        "sortName": "Deathly Hallows, Harry Potter",
                        "languageId": 120,
                        "primary": true
                    },
                    "workType": {
                        "id": 1,
                        "label": "Novel"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "work",
                "_id": "f94d74ce-c748-4130-8d59-38b290af8af3",
                "_score": 21.478561,
                "_source": {
                    "bbid": "f94d74ce-c748-4130-8d59-38b290af8af3",
                    "dataId": 2387,
                    "revisionId": 7683,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 6632,
                    "typeId": 5,
                    "aliasSetId": 6022,
                    "identifierSetId": 1956,
                    "relationshipSetId": null,
                    "type": "Work",
                    "languageSetId": 3583,
                    "defaultAlias": {
                        "id": 6632,
                        "name": "Harry Potter and the Cursed Child",
                        "sortName": "Cursed Child, Harry Potter",
                        "languageId": 120,
                        "primary": true
                    },
                    "workType": {
                        "id": 5,
                        "label": "Play"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "work",
                "_id": "7c92a79a-21cc-423d-89b9-55cc4d6dfe4a",
                "_score": 20.971832,
                "_source": {
                    "bbid": "7c92a79a-21cc-423d-89b9-55cc4d6dfe4a",
                    "dataId": 2720,
                    "revisionId": 8734,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 3655,
                    "typeId": 1,
                    "aliasSetId": 3215,
                    "identifierSetId": null,
                    "relationshipSetId": null,
                    "type": "Work",
                    "languageSetId": 1940,
                    "defaultAlias": {
                        "id": 3655,
                        "name": "Harry Potter and the Half-Blood Prince",
                        "sortName": "Prince, Harry Potter and the Half-Blood",
                        "languageId": 284,
                        "primary": true
                    },
                    "workType": {
                        "id": 1,
                        "label": "Novel"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "work",
                "_id": "36c00546-ce24-4a67-9bd8-a1658bb80d6f",
                "_score": 19.991718,
                "_source": {
                    "bbid": "36c00546-ce24-4a67-9bd8-a1658bb80d6f",
                    "dataId": 1033,
                    "revisionId": 3408,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 2244,
                    "typeId": 1,
                    "aliasSetId": 1935,
                    "identifierSetId": null,
                    "relationshipSetId": null,
                    "type": "Work",
                    "languageSetId": 1283,
                    "defaultAlias": {
                        "id": 2244,
                        "name": "Harry Potter and the Goblet of Fire",
                        "sortName": "Fire, Harry Potter and the Goblet of",
                        "languageId": 120,
                        "primary": true
                    },
                    "workType": {
                        "id": 1,
                        "label": "Novel"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "work",
                "_id": "37b918f8-cc5e-40df-8da9-e5439480debd",
                "_score": 19.702787,
                "_source": {
                    "bbid": "37b918f8-cc5e-40df-8da9-e5439480debd",
                    "dataId": 1658,
                    "revisionId": 5252,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 4182,
                    "typeId": 1,
                    "aliasSetId": 3673,
                    "identifierSetId": null,
                    "relationshipSetId": null,
                    "type": "Work",
                    "languageSetId": 2195,
                    "defaultAlias": {
                        "id": 4182,
                        "name": "Harry Potter and the Chamber of Secrets",
                        "sortName": "Harry Potter and the Chamber of Secrets",
                        "languageId": 120,
                        "primary": true
                    },
                    "workType": {
                        "id": 1,
                        "label": "Novel"
                    }
                }
            },
            {
                "_index": "bookbrainz",
                "_type": "work",
                "_id": "b2d19b45-117d-437d-b55b-7fff01e29603",
                "_score": 19.702787,
                "_source": {
                    "bbid": "b2d19b45-117d-437d-b55b-7fff01e29603",
                    "dataId": 595,
                    "revisionId": 1894,
                    "master": true,
                    "annotationId": null,
                    "disambiguationId": null,
                    "defaultAliasId": 1229,
                    "typeId": 1,
                    "aliasSetId": 1190,
                    "identifierSetId": 1228,
                    "relationshipSetId": 1280,
                    "type": "Work",
                    "languageSetId": 922,
                    "defaultAlias": {
                        "id": 1229,
                        "name": "Harry Potter and the Chamber of Secrets",
                        "sortName": "Harry Potter and the Chamber of Secrets",
                        "languageId": 120,
                        "primary": true
                    },
                    "workType": {
                        "id": 1,
                        "label": "Novel"
                    }
                }
            }
        ]
    }
}

@MonkeyDo MonkeyDo force-pushed the akhilesh26:search_api branch from aad1dd6 to 405505e Aug 27, 2019

@MonkeyDo

This comment has been minimized.

Copy link
Contributor

commented Aug 27, 2019

After some tinkering, I was able to set Travis to run an instance of elasticsearch when running the tests, so we don't need to try to mock it.
My attemps at mocking ES were pretty unsuccessful, and I think this is better in any case.

I also modified the tests to create more entities, and ensure only the correct subset is returned (with the right name, and with the collection filtering)

router.get('/', async (req, res) => {
const {orm} = req.app.locals;
const query = req.query.q;
const collection = req.query.collection || null;

This comment has been minimized.

Copy link
@MonkeyDo

MonkeyDo Aug 27, 2019

Contributor

After some thought, instead of collection, I think it would be clearer to use type to represent the entity type, as we use the term 'entity type' in the api docs in various places.

It would also be closer to the MusicBrainz implementation which is always a plus: https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2/Search

And finally, if we end up having user collections in the future and decide to call them 'collection', it will prevent confusion.

This comment has been minimized.

Copy link
@akhilesh26

akhilesh26 Aug 30, 2019

Author Contributor

I did entityType, it is more clear than type because the type is used to under entity. Means type of work, type of publisher extra.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.