<commit_before>SearchResults = require 'views/search_results'

class Search extends Backbone.View
  initialize: (options) ->
    @projectCollection = options.projectCollection
    @searchResults = new SearchResults

  events: 
    'keypress .search-query' : 'searchCollection'
    'blur' : 'stopSearch'

  render: (query) =>
    projectResults = @projectCollection.filter (project) ->
      not _.isEmpty(project.get('name').match query)
    @$el.append @searchResults.render(projectResults).el
    @

  searchCollection: (e) =>
    if e.which is 13
      @stopSearch e
    else
      query = @$('.search-query').val()
      @render new RegExp query

  stopSearch: (e) =>
    if e.type is 'focusout' or e.which is 13
      @searchResults.remove()


module.exports = Search<commit_msg>Improve search<commit_after>SearchResults = require 'views/search_results'

class Search extends Backbone.View
  initialize: (options) ->
    @projectCollection = options.projectCollection
    @searchResults = new SearchResults

  events: 
    'keyup .search-query' : 'searchCollection'
    'blur .search-query' : 'stopSearch'

  render: (projectResults) =>
    @$el.append @searchResults.render(projectResults).el
    @

  searchCollection: (e) =>
    if e.which is 13
      @stopSearch e
    else
      query = new RegExp e.currentTarget.value
      results = @projectCollection.filter (project) ->
        not _.isEmpty(project.get('name').toLowerCase().match query)
      @render(results)

  stopSearch: (e) =>
    if e.type is 'focusout' or e.which is 13
      setTimeout @searchResults.remove, 10

module.exports = Search
{'fraction_non_alphanumeric': 0.11731843575418995, 'fraction_numerical': 0.006207324643078833, 'mean_word_length': 3.3450134770889486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4787244', 'n_tokens_mistral': 492, 'n_tokens_neox': 470, 'n_words': 118}