src/index.js
function presentResults (graph, reverseMap, rawResults, query) {
  var nodesWithLocales = rawResults.map(r => reverseMap[r])

  var canonicalNodesWithPaths = nodesWithLocales.reduce((canonicalNodes, nwl) => {
    return canonicalNodes.concat(findCanonicalNodeWithPath(graph, nwl.node, nwl.locale, []))
  }, [])

  const canonicalNodesWithPathsAndWeights = canonicalNodesWithPaths.map(cnwp => addWeight(cnwp, query))

  canonicalNodesWithPathsAndWeights.sort(byWeightAndThenAlphabetically)

  const uniqueNodesWithPathsAndWeights = uniqBy(canonicalNodesWithPathsAndWeights, (cnwp) => {
    return presentableName(cnwp.node, preferredLocale)
  })

  uniqueNodesWithPathsAndWeights.sort(byWeightAndThenAlphabetically)

  var presentableNodes = uniqueNodesWithPathsAndWeights.map(cnwp => {
    var canonicalName = presentableName(cnwp.node, preferredLocale)
    var pathToName = ''
    if (showPaths && cnwp.path.length) {
      var stableNamesInPath = cnwp.path
        .filter(pathNode => pathNode.node.meta['stable-name'])
        .map(pathNode => presentableName(pathNode.node, pathNode.locale))
      var lastNode = stableNamesInPath.pop()
      if (lastNode) {
        pathToName = lastNode
      }
    }
    return {
      name: canonicalName,
      path: pathToName
    }
  })

  return presentableNodes
}
function presentResults (graph, reverseMap, rawResults, query) {
  var nodesWithLocales = rawResults.map(r => reverseMap[r])

  var canonicalNodesWithPaths = nodesWithLocales.reduce((canonicalNodes, nwl) => {
    return canonicalNodes.concat(findCanonicalNodeWithPath(graph, nwl.node, nwl.locale, []))
  }, [])

  const canonicalNodesWithPathsAndWeights = canonicalNodesWithPaths.map(cnwp => addWeight(cnwp, query))

  canonicalNodesWithPathsAndWeights.sort(byWeightAndThenAlphabetically)

  const uniqueNodesWithPathsAndWeights = uniqBy(canonicalNodesWithPathsAndWeights, (cnwp) => {
    return presentableName(cnwp.node, preferredLocale)
  })

  uniqueNodesWithPathsAndWeights.sort(byWeightAndThenAlphabetically)

  var presentableNodes = uniqueNodesWithPathsAndWeights.map(cnwp => {
    var canonicalName = presentableName(cnwp.node, preferredLocale)
    var pathToName = ''
    if (showPaths && cnwp.path.length) {
      var stableNamesInPath = cnwp.path
        .filter(pathNode => pathNode.node.meta['stable-name'])
        .map(pathNode => presentableName(pathNode.node, pathNode.locale))
      var lastNode = stableNamesInPath.pop()
      if (lastNode) {
        pathToName = lastNode
      }
    }
    return {
      name: canonicalName,
      path: pathToName
    }
  })

  return presentableNodes
}
function presentResults ( graph , reverseMap , rawResults , query ) { var nodesWithLocales = rawResults . map ( r => reverseMap [ r ] ) var canonicalNodesWithPaths = nodesWithLocales . reduce ( ( canonicalNodes , nwl ) => { return canonicalNodes . concat ( findCanonicalNodeWithPath ( graph , nwl . node , nwl . locale , [ ] ) ) } , [ ] ) const canonicalNodesWithPathsAndWeights = canonicalNodesWithPaths . map ( cnwp => addWeight ( cnwp , query ) ) canonicalNodesWithPathsAndWeights . sort ( byWeightAndThenAlphabetically ) const uniqueNodesWithPathsAndWeights = uniqBy ( canonicalNodesWithPathsAndWeights , ( cnwp ) => { return presentableName ( cnwp . node , preferredLocale ) } ) uniqueNodesWithPathsAndWeights . sort ( byWeightAndThenAlphabetically ) var presentableNodes = uniqueNodesWithPathsAndWeights . map ( cnwp => { var canonicalName = presentableName ( cnwp . node , preferredLocale ) var pathToName = '' if ( showPaths && cnwp . path . length ) { var stableNamesInPath = cnwp . path . filter ( pathNode => pathNode . node . meta [ 'stable-name' ] ) . map ( pathNode => presentableName ( pathNode . node , pathNode . locale ) ) var lastNode = stableNamesInPath . pop ( ) if ( lastNode ) { pathToName = lastNode } } return { name : canonicalName , path : pathToName } } ) return presentableNodes }
Engine gives us back a list of results that includes synonyms, typos, endonyms and other things we don't want the user to see. This function transforms those into a list of stable canonical country names.
Engine gives us back a list of results that includes synonyms typos endonyms and other things we don t want the user to see . This function transforms those into a list of stable canonical country names .