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

search package #152

Merged
merged 33 commits into from
May 14, 2019
Merged

search package #152

merged 33 commits into from
May 14, 2019

Conversation

pranavkulkarni
Copy link
Contributor

@pranavkulkarni pranavkulkarni commented Apr 9, 2019

Module to search for ArcGIS items and format them for display in ArcGIS Hub

Structure --

src
  ago
    helpers
      aggs
      filters
      format
      page
      sort
    search.ts // searches for items and returns raw ago results
    params.ts // defines ISearchParams interface to hub.js/search
    serialize.ts // serialize raw UI params into query parameters that V3 understands
    format-item-collection.ts // format raw ago results into hub v3 style datasets
    compute-items-facets.ts // compute aggs/facets based on ago results and also calculate aggs for custom facets

Sample of how this will be used in UI code --

const authentication = new arcgisRest.UserSession({
      portal: 'https://qaext.arcgis.com/sharing/rest',
      username: 'dcadminqa',
      password: 'dcadminqa1'
    })
    const portal = 'https://qaext.arcgis.com/sharing/rest'
    const params = {
      q: 'crime',
      sort: 'name',
      agg: { fields: 'tags,collection,owner,source,hasApi,downloadable' },
      start: 1,
      num: 10
    }
    authentication.getToken(portal)
    .then(token => {
      const headers = { authorization: token, portal }
      const serializedParams = arcgisHub.serialize(params)
      console.log(serializedParams)
      return fetch(`hub.arcgis.com/api/v3/search?${serializedParams}`, { headers })
    })
    .then(unifiedResultsPromise => {
      return unifiedResultsPromise.json()
    })
    .then(unifiedResults => {
      console.log(unifiedResults)
      // UPDATE UI model with unified results
    })

Sample of how hub indexer api v3 new search route will use hub.js --

   const search = require('@esri/hub-search')

  // 1. perform ago search with facets and formatting
  const agoResults = await search.agoSearch(req.query, req.headers.authorization, req.headers.portal)

  // 2. compute items facets
  const facets = await search.computeItemsFacets(agoResults.aggregations, req.query, req.headers.authorization, req.headers.portal)

  // 3. format item collection based on actual search results and computed facets
  const model = search.agoFormatItemCollection(agoResults, facets, req.query)

  return model

@codecov
Copy link

codecov bot commented Apr 9, 2019

Codecov Report

Merging #152 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #152    +/-   ##
======================================
  Coverage     100%   100%            
======================================
  Files          57     86    +29     
  Lines         897   1233   +336     
  Branches      117    185    +68     
======================================
+ Hits          897   1233   +336
Impacted Files Coverage Δ
packages/annotations/src/util.ts 100% <ø> (ø) ⬆️
...ckages/search/src/ago/helpers/aggs/downloadable.ts 100% <100%> (ø)
...ackages/search/src/ago/helpers/aggs/create-aggs.ts 100% <100%> (ø)
packages/search/src/ago/format-item-collection.ts 100% <100%> (ø)
packages/search/src/ago/helpers/format/index.ts 100% <100%> (ø)
packages/common/src/index.ts 100% <100%> (ø) ⬆️
...s/search/src/ago/helpers/filters/encode-filters.ts 100% <100%> (ø)
packages/search/src/ago/search.ts 100% <100%> (ø)
packages/search/src/ago/helpers/filters/has-api.ts 100% <100%> (ø)
...ckages/search/src/ago/helpers/filters/group-ids.ts 100% <100%> (ø)
... and 51 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 13a6374...4de4434. Read the comment docs.

@jPurush
Copy link
Contributor

jPurush commented Apr 9, 2019

Can we add a README similar to one from the other packages ?

@pranavkulkarni
Copy link
Contributor Author

Yes, I will once this PR is complete. The scope of this package is still in the works.

Copy link
Contributor

@jgravois jgravois left a comment

Choose a reason for hiding this comment

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

very cool!

i've jotted down some initial thoughts...

.gitignore Outdated Show resolved Hide resolved
packages/search/package.json Outdated Show resolved Hide resolved
packages/search/src/ago/format-item.ts Outdated Show resolved Hide resolved
packages/search/src/ago/encode-ago-query.ts Outdated Show resolved Hide resolved
packages/search/src/ago/search.ts Outdated Show resolved Hide resolved
packages/search/src/common/create-filters.ts Outdated Show resolved Hide resolved
packages/search/src/common/params.ts Outdated Show resolved Hide resolved
packages/search/src/index.ts Outdated Show resolved Hide resolved
tsconfig.json Outdated Show resolved Hide resolved
Copy link
Member

@haoliangyu haoliangyu left a comment

Choose a reason for hiding this comment

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

General comments after a quick scan:

  • There should be room to simplify the creation of AGO query parameters. The logic is complicated in opendata-ui because it needs to search both AGO and Hub backend, but it is simpler here.
  • There should be interface(s) to define the search results in JSONAPI.

packages/search/src/ago/create-q.ts Outdated Show resolved Hide resolved
packages/search/src/ago/format-item.ts Outdated Show resolved Hide resolved
packages/search/src/ago/helpers/calc-start.ts Outdated Show resolved Hide resolved
packages/search/src/ago/helpers/handle-filter.ts Outdated Show resolved Hide resolved
packages/search/src/ago/helpers/downloadable.ts Outdated Show resolved Hide resolved
packages/search/src/ago/helpers/sort.ts Outdated Show resolved Hide resolved
packages/search/src/common/hub-type-map.ts Outdated Show resolved Hide resolved
packages/search/src/ago/search.ts Outdated Show resolved Hide resolved
packages/search/src/ago/format-item.ts Outdated Show resolved Hide resolved
packages/search/src/common/params.ts Outdated Show resolved Hide resolved
@jgravois jgravois mentioned this pull request May 1, 2019
@jgravois jgravois dismissed their stale review May 8, 2019 00:00

[WIP] search package (#152)

@jgravois jgravois self-requested a review May 8, 2019 00:00
@jgravois
Copy link
Contributor

jgravois commented May 8, 2019

i accidentally dismissed @haoliangyu's review, but i think all his feedback was addressed anyway.

@pranavkulkarni is this PR ready for another round of code review?

@jgravois jgravois requested a review from tomwayson May 8, 2019 00:02
@pranavkulkarni pranavkulkarni changed the title [WIP] search package search package May 8, 2019
@pranavkulkarni
Copy link
Contributor Author

@jgravois this PR is ready

Copy link
Contributor

@jgravois jgravois left a comment

Choose a reason for hiding this comment

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

true hero's work @pranavkulkarni.

it looks like you haven't done much in the way of properly formatted TSDoc to ensure that folks outside of tugboat will be able to visit our documentation and grok how your first order methods work.

to be fair though, our existing initiative admin methods are every bit as opaque as the stuff you're adding here.

after you deal with my (minor) quips, this seems ready to :shipit:

@@ -0,0 +1,61 @@
{
"name": "@esri/hub-search",
"version": "1.11.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, but we released v2.0.0 when you were out on monday. if you update this lerna can help us release v2.1.0 afterward with your new package.

"@esri/arcgis-rest-portal": "^2.0.0",
"@esri/arcgis-rest-request": "^2.0.0",
"@esri/arcgis-rest-types": "^2.0.0",
"@esri/hub-common": "^1.11.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

"@esri/hub-common": "^2.0.0"

"@esri/arcgis-rest-portal": "^2.0.0",
"@esri/arcgis-rest-request": "^2.0.0",
"@esri/arcgis-rest-types": "^2.0.0",
"@esri/hub-common": "^1.11.1"
Copy link
Contributor

@jgravois jgravois May 8, 2019

Choose a reason for hiding this comment

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

"@esri/hub-common": "^2.0.0"


import { ISearchOptions } from "@esri/arcgis-rest-portal";

export interface ISearchParams extends ISearchOptions {
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm not a big fan of conflating Params and RequestOptions here, but @dbouwman resisted my attempts to enforce method signatures that dig everything out of a single argument too.

what i guess i'm saying is, 'carry on'.

{},
customAggsFunctions[customAgg](agoAggregations)
);
facets3 = Object.assign({}, facets3, format(rawCounts));
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm not sure if it helps with Object.assign() too but i'm under the impression that tslib optimizes the destructuring we're doing everywhere else.

const facets3 = { ...format(rawCounts) }

@@ -0,0 +1,21 @@
import { getProp } from "@esri/hub-common";
const apiTypes = ["Feature Service", "Map Service", "Image Service"];
Copy link
Contributor

Choose a reason for hiding this comment

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

i feel like you're declaring this in at least two different places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I'll move it to hub-common

import { getProp } from "@esri/hub-common";
const apiTypes = ["Feature Service", "Map Service", "Image Service"];

export function hasApi(queryFilters: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

when this library is bundled as a UMD all the methods hang off of an arcgisHub namespace.

this means that in the browser, filters.hasApi will collide with aggs.hasApi

Copy link
Contributor Author

@pranavkulkarni pranavkulkarni May 9, 2019

Choose a reason for hiding this comment

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

Interesting... the UI is not supposed to calls these functions directly. They are being used by agoSearch and computeItemsFacets that are exposed by this library and the UI will talk to just those functions. Do I have to still rename them?

Copy link
Contributor

Choose a reason for hiding this comment

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

i didn't see before that you included "hasApi" in the blacklist. thats definitely good.

even if callers that load the UMD don't call these methods directly though, things will go pear shaped when they're called internally, because i don't think there is a mechanism in place in that build to differentiate them.

you have two options:

  1. make the names unique, just to be safe.
  2. test loading the UMD in the browser and calling both methods that lean on hasApi internally to confirm that i'm wrong.

@jgravois
Copy link
Contributor

jgravois commented May 8, 2019

can you give this a once over too @tomwayson?

@pranavkulkarni
Copy link
Contributor Author

Thanks @jgravois I will address the points you raised here. I will also beautify comments.

@@ -8116,6 +8116,7 @@
"color-convert": "^1.9.0"
}
},
<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

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

this is what Travis is choking on.

besides fixing it manually, you're also welcome to just delete the file and rerun npm install in the root of the repo to recreate it.

@jgravois jgravois merged commit 722a931 into master May 14, 2019
@jgravois
Copy link
Contributor

i'll release Hub.js v2.1.0 tomorrow.

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

Successfully merging this pull request may close these issues.

4 participants