Skip to content

Commit

Permalink
fix(hub-common): add sorting, uris to _searchContent
Browse files Browse the repository at this point in the history
  • Loading branch information
dbouwman committed Oct 29, 2021
1 parent d1a23d4 commit b285ddf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
17 changes: 13 additions & 4 deletions packages/common/src/search/_searchContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ export async function _searchContent(
so.countFields = options.aggregations.join(",");
so.countSize = 200;
}
// copy over various options
// TODO: Dry this up
if (options.num) {
so.num = options.num;
}
return searchPortal(so, options.siteModel);
if (options.sortField) {
so.sortField = options.sortField;
}
if (options.sortOrder) {
so.sortOrder = options.sortOrder;
}
return searchPortal(so, options.site);
} else {
// Hub API Search
// TODO: Implement hub api content search
Expand All @@ -69,12 +77,13 @@ export async function _searchContent(

function searchPortal(
searchOptions: ISearchOptions,
siteModel?: IModel
site?: string | IModel
): Promise<IContentSearchResult> {
return searchItems(searchOptions).then((resp) => {
let content = resp.results.map(itemToContent);
if (siteModel) {
content = content.map((entry) => setContentSiteUrls(entry, siteModel));
if (site && typeof site === "object") {
// TODO: update once setContentSiteUrls handles strings in addition to model
content = content.map((entry) => setContentSiteUrls(entry, site));
}
// convert aggregations into facets
const facets = convertPortalResponseToFacets(resp);
Expand Down
3 changes: 1 addition & 2 deletions packages/common/src/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,7 @@ export interface IMatchOptions {
* Search Options
*/
export interface IHubSearchOptions {
site?: string;
siteModel?: IModel;
site?: string | IModel;
authentication?: UserSession;
sortField?: string;
sortOrder?: "desc" | "asc";
Expand Down
6 changes: 4 additions & 2 deletions packages/common/test/search/_searchContent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("_searchContent:", () => {
term: "water",
};
const opts: IHubSearchOptions = {
siteModel: {
site: {
item: {
url: "https://foo.com",
} as Portal.IItem,
Expand All @@ -60,7 +60,7 @@ describe("_searchContent:", () => {
expect(content.urls.site).toContain("https://foo.com");
});

it("search with aggregations", async () => {
it("search with aggregations and sorting", async () => {
const searchItemsSpy = spyOn(Portal, "searchItems").and.callFake(() => {
return Promise.resolve(cloneObject(AggResponse));
});
Expand All @@ -71,6 +71,8 @@ describe("_searchContent:", () => {
const opts: IHubSearchOptions = {
apis: ["arcgis"],
aggregations: ["tags", "access"],
sortField: "title",
sortOrder: "desc",
};

const res = await _searchContent(f, opts);
Expand Down

0 comments on commit b285ddf

Please sign in to comment.