 # Helper functions
 ################################
 
-    $scope.findFacet = (typeName, res) ->
+    findFacet = (typeName, res) ->
       if res != null and res.facets.content_type
          facets = (facet.val for facet in res.facets.content_type.buckets)
          return facets.indexOf(typeName)
       else
          return -1
 
-    $scope.getTypeCounts = (type, res) ->
-      idx = $scope.findFacet(type, res)
+    getTypeCounts = (type, res) ->
+      idx = findFacet(type, res)
       console.log(idx)
       if idx < 0
         return null
       return res?.facets?.content_type?.buckets[idx].count ? 0
 
-    $scope.findResult = (typeName, res) ->
+    findResult = (typeName, res) ->
       console.log("RESULT IS", res)
       if res != null
         groups = (group.groupValue for group in res.grouped.content_type.groups)

      else
        return -1

    $scope.getSpelling = (res) ->
      return res.spellcheck.suggestions

    $scope.getCollation = (res) ->
      if res.spellcheck?.collations.length > 0
        return res.spellcheck.collations[1].collationQuery
      return null

    $scope.getResults = (type, res) ->
      idx = $scope.findResult(type, res)
      if idx < 0
        return null
      return res.grouped.content_type.groups[idx].doclist

    $scope.getVolumeFeatureBoxOpts = ->
      opts = [$scope.selectSessionStr, $scope.selectHighlightStr]
      return opts

    $scope.getPartyFeatureBoxOpts = ->
      opts = [$scope.selectSessionStr, $scope.selectHighlightStr]
      return opts

    $scope.updateFilterBoxOptions = ->
      console.log("SELTYPE", $scope.selectedType)
      if $scope.selectedType and currentFilter != $scope.selectedType
        # We have to reset offset
        $scope.offset = 0
        if $scope.selectedType.join(" ").includes($scope.volumeDisplayStr)
          $scope.filterDisplay = (s for s in $scope.getVolumeFeatureBoxOpts())
        if $scope.selectedType.join(" ").includes($scope.partyDisplayStr)
          # console.log("AFFILIATIONS:", $scope.affiliations)
          $scope.filterDisplay = (s for s in $scope.selectPeopleFilters)

      $scope.query = $scope.originalQuery
      $scope.offset = 0
      console.log("NEW SEARCH:", $scope.query)
      search()

    # Def search: the function that is actually calling the search from Haskell.
    # Get the results from Solr and pass them into parseResults.
    search = (query = "") ->
      # This is for if we want to pass an argument into this...
      if query.length > 0
        $scope.query = query
