<commit_before><?php
/**
 * Search class for frontend users to search for events.
 * 
 * 
 * @package UNL_UCBCN_Frontend
 * @author <NAME>
 */

require_once 'UNL/UCBCN/Frontend.php';
require_once 'UNL/UCBCN/EventListing.php';

class UNL_UCBCN_Frontend_Search extends UNL_UCBCN_Frontend
{
    var $calendar;
    var $output;
    var $query;
    var $starttime;
    var $endtime;
    
    function __construct($options=array())
	{
	    $this->view = 'search';
		$this->setOptions($options);
		$this->run();
	}
    
    function run()
    {
        $this->query = trim($this->query);
        if (!empty($this->query)) {
            $mdb2 = $this->calendar->getDatabaseConnection();
            $sql = 'SELECT eventdatetime.id FROM event, eventdatetime, calendar_has_event WHERE ' .
						'eventdatetime.event_id = event.id AND 
						calendar_has_event.event_id = event.id AND 
						calendar_has_event.status != \'pending\' AND ';
			if ($t = strtotime($this->query)) {
				// This is a time...
				$sql .= 'eventdatetime.starttime LIKE \''.date('Y-m-d',$t).'%\' ORDER BY eventdatetime.starttime';
			} else {
				// Do a textual search.
				$sql .= 'event.title LIKE \'%'.$mdb2->escape($this->query).'%\' ORDER BY event.title';
			}
			
			$res = $mdb2->query($sql);
			$this->output = new UNL_UCBCN_EventListing();
			while ($row = $res->fetchRow()) {
				$this->output->events[] =  new UNL_UCBCN_EventInstance($row[0]);
			}
        } else {
            $this->output = 'Enter a search string to search for events.';
        }
    }
    
}

?><commit_msg>Add DISTINCT to the search query to eliminate duplicates being returned.<commit_after><?php
/**
 * Search class for frontend users to search for events.
 * 
 * 
 * @package UNL_UCBCN_Frontend
 * @author <NAME>
 */

require_once 'UNL/UCBCN/Frontend.php';
require_once 'UNL/UCBCN/EventListing.php';

class UNL_UCBCN_Frontend_Search extends UNL_UCBCN_Frontend
{
    var $calendar;
    var $output;
    var $query;
    var $starttime;
    var $endtime;
    
    function __construct($options=array())
	{
	    $this->view = 'search';
		$this->setOptions($options);
		$this->run();
	}
    
    function run()
    {
        $this->query = trim($this->query);
        if (!empty($this->query)) {
            $mdb2 = $this->calendar->getDatabaseConnection();
            $sql = 'SELECT DISTINCT eventdatetime.id FROM event, eventdatetime, calendar_has_event WHERE ' .
						'eventdatetime.event_id = event.id AND 
						calendar_has_event.event_id = event.id AND 
						calendar_has_event.status != \'pending\' AND ';
			if ($t = strtotime($this->query)) {
				// This is a time...
				$sql .= 'eventdatetime.starttime LIKE \''.date('Y-m-d',$t).'%\' ORDER BY eventdatetime.starttime';
			} else {
				// Do a textual search.
				$sql .= 'event.title LIKE \'%'.$mdb2->escape($this->query).'%\' ORDER BY event.title';
			}
			
			$res = $mdb2->query($sql);
			$this->output = new UNL_UCBCN_EventListing();
			while ($row = $res->fetchRow()) {
				$this->output->events[] =  new UNL_UCBCN_EventInstance($row[0]);
			}
        } else {
            $this->output = 'Enter a search string to search for events.';
        }
    }
    
}

?>
{'fraction_non_alphanumeric': 0.16069182389937106, 'fraction_numerical': 0.0025157232704402514, 'mean_word_length': 2.7291910902696364, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, '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': '4582439', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1081, 'n_words': 231}