<commit_before>//
//  SearchBooksTableViewController.swift
//  Bookr
//
//  Created by Student on 3/7/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit

class SearchBooksTableViewController: UITableViewController {
    let searchController = UISearchController(searchResultsController: nil)
    
    var books = [Book]()
    
    // Crie uma propriedade na sua classe para armazenar os resultados do seu filtro
    
    var filteredBooks = [Book]()
    
    // 4. Crie o método de filtragem dos dados com base no texto digitado
    func filterContent(for searchText: String, scope: String = "All") {
        filteredBooks = books.filter({ books in
            return (books.name.lowercased().contains(searchText.lowercased()))
        })
        
        tableView.reloadData()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        books = BookDAO.searchAll()
        
        searchController.searchResultsUpdater = self // Por enquanto terá um erro aqui, mas ele some no passo numero 5
        searchController.dimsBackgroundDuringPresentation = false
        definesPresentationContext = true
        tableView.tableHeaderView = searchController.searchBar
        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false
        
        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    // MARK: - Table view data source<commit_msg>Changes<commit_after>//
//  SearchBooksTableViewController.swift
//  Bookr
//
//  Created by Student on 3/7/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit

class SearchBooksTableViewController: UITableViewController {
    let searchController = UISearchController(searchResultsController: nil)
    
    var books = [Book]()
    
    // Crie uma propriedade na sua classe para armazenar os resultados do seu filtro
    
    var filteredBooks = [Book]()
    
    // 4. Crie o método de filtragem dos dados com base no texto digitado
    func filterContent(for searchText: String, scope: String = "All") {
        filteredBooks = books.filter({ books in
            return (books.name.lowercased().contains(searchText.lowercased()))
        })
        
        tableView.reloadData()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        books = BookDAO.searchAll()
        
        searchController.searchResultsUpdater = self // Por enquanto terá um erro aqui, mas ele some no passo numero 5
        searchController.dimsBackgroundDuringPresentation = false
        definesPresentationContext = true
        tableView.tableHeaderView = searchController.searchBar
        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false
        
        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        books = BookDAO.searchAll()
        reloadInputViews()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    // MARK: - Table view data source
{'fraction_non_alphanumeric': 0.07461054933041815, 'fraction_numerical': 0.005465974309920744, 'mean_word_length': 2.546511627906977, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5205153', 'n_tokens_mistral': 993, 'n_tokens_neox': 952, 'n_words': 295}