<commit_before>Bandango.SearchMixin = Ember.Mixin.create
  searchTimeout: 300
  cached: {}

  searchResultsEmpty: (->
    not (@get("searchResults.length") > 0) and not @get("searchQueryEmpty") and not @get("isQuerying")
  ).property("searchResults", "searchQueryEmpty", "isQuerying")

  searchQueryEmpty: (->
    Ember.isEmpty @get("currentQuery")
  ).property("currentQuery")

  emptyQuerySearch: ->
    Ember.debug "#emptyQuerySearch. Override this method"

  executeSearch: ->
    Ember.debug "#executeSearch. Override this method"

  getCacheKey: (results) ->
    if results and results.meta and results.meta.query
      results.meta.query.underscore()
    else
      @get("currentQuery")

  gotResults: (searchResults) ->
    @set "isQuerying", false
    cacheKey = @getCacheKey(searchResults)
    @cached[cacheKey] = searchResults
    @set "searchResults", searchResults

  stopScheduledSearch: ->
    if scheduledId = @get("scheduledSearchId")
      clearTimeout scheduledId
      @set "scheduledSearchId", null

  scheduleSearch: ->
    @set "isQuerying", true
    @stopScheduledSearch()
    scheduledSearchId = setTimeout $.proxy(@executeSearch, @), @get("searchTimeout")
    @set "scheduledSearchId", scheduledSearchId

  cachedQueryResults: (term) ->
    @cached[term.underscore()]

  queryChanged: (newQuery) ->
    if Ember.isEmpty(newQuery)
      @stopScheduledSearch()
      @emptyQuerySearch()
    else if !!@cachedQueryResults(newQuery)
      @gotResults @cachedQueryResults(newQuery)
    else
      @scheduleSearch()
    @set "currentQuery", newQuery<commit_msg>enhanced search implementation<commit_after>Bandango.SearchMixin = Ember.Mixin.create
  searchTimeout: 300
  cached: {}

  searchResultsEmpty: (->
    not (@get("searchResults.length") > 0) and not @get("searchQueryEmpty") and not @get("isQuerying")
  ).property("searchResults", "searchQueryEmpty", "isQuerying")

  searchQueryEmpty: (->
    Ember.isEmpty @get("currentQuery")
  ).property("currentQuery")

  emptyQuerySearch: ->
    Ember.debug "#emptyQuerySearch. Override this method"

  executeSearch: ->
    Ember.debug "#executeSearch. Override this method"

  getCacheKey: (results) ->
    if results and results.meta and results.meta.query
      results.meta.query.underscore()

  gotResults: (searchResults) ->
    @set "isQuerying", false
    cacheKey = @getCacheKey(searchResults)
    if cacheKey
      @cached[cacheKey] = searchResults
    @set "searchResults", searchResults

  stopScheduledSearch: ->
    if scheduledId = @get("scheduledSearchId")
      clearTimeout scheduledId
      @set "scheduledSearchId", null

  scheduleSearch: ->
    @set "isQuerying", true
    @stopScheduledSearch()
    scheduledSearchId = setTimeout $.proxy(@executeSearch, @), @get("searchTimeout")
    @set "scheduledSearchId", scheduledSearchId

  cachedQueryResults: (term) ->
    @cached[term.underscore()]

  queryChanged: (newQuery) ->
    if Ember.isEmpty(newQuery)
      @stopScheduledSearch()
      @emptyQuerySearch()
    else if !!@cachedQueryResults(newQuery)
      @stopScheduledSearch()
      @gotResults @cachedQueryResults(newQuery)
    else
      @scheduleSearch()
    @set "currentQuery", newQuery
{'fraction_non_alphanumeric': 0.12413793103448276, 'fraction_numerical': 0.0025078369905956114, 'mean_word_length': 4.097444089456869, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2363280', 'n_tokens_mistral': 960, 'n_tokens_neox': 932, 'n_words': 196}