<commit_before><?php

/**
 * A dropdown field with ajax loaded options list, uses jquery select2
 * http://ivaynberg.github.io/select2/
 * @author <EMAIL>
 **/
class AjaxSelect2Field extends TextField{

	private static $allowed_actions = array('search');
	
	protected $config = array(
		'classToSearch' 		=> 'SiteTree',
		'searchFields' 			=> array('Title'),
		'resultsLimit' 			=> 200,
		'minimumInputLength' 	=> 2,
		'resultsFormat' 		=> '$Title',
		'selectionFormat' 		=> '$Title',
		'placeholder'			=> 'Search...'
	);


	function Field($properties = array()){
		Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
		Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
		Requirements::javascript(SELECT2_MODULE . "/select2/select2.js");
		Requirements::javascript(SELECT2_MODULE . '/javascript/ajaxselect2.init.js');
		Requirements::css(SELECT2_MODULE . "/select2/select2.css");
		return parent::Field($properties);
	}


	public function search($request){
		$list = DataList::create($this->getConfig('classToSearch'));
		
		$params = array();
		$searchFields = $this->getConfig('searchFields');
		foreach($searchFields as $searchField) {
			$name = (strpos($searchField, ':') !== FALSE) ? $searchField : "$searchField:StartsWith";
			$params[$name] = $request->getVar('term');
		}	
		$start = (int)$request->getVar('id') ? (int)$request->getVar('id') * $this->getConfig('resultsLimit') : 0;
		$list = $list->filterAny($params);
		$total = $list->count();
		$results = $list->sort(strtok($searchFields[0], ':'), 'ASC')->limit($this->getConfig('resultsLimit'), $start);
		
		$return = array(
			'list' => array(),
			'total' => $total
		);

		$originalSourceFileComments = Config::inst()->get('SSViewer', 'source_file_comments');
		Config::inst()->update('SSViewer', 'source_file_comments', false);
		foreach($results as $object) {
			$return['list'][] = array(
				'id' => $object->ID,
				'resultsContent' => html_entity_decode(SSViewer::fromString($this->getConfig('resultsFormat'))->process($object)),
				'selectionContent' => SSViewer::fromString($this->getConfig('selectionFormat'))->process($object)<commit_msg>search method partialMatch instead of startsWith<commit_after><?php

/**
 * A dropdown field with ajax loaded options list, uses jquery select2
 * http://ivaynberg.github.io/select2/
 * @author <EMAIL>
 **/
class AjaxSelect2Field extends TextField{

	private static $allowed_actions = array('search');
	
	protected $config = array(
		'classToSearch' 		=> 'SiteTree',
		'searchFields' 			=> array('Title'),
		'resultsLimit' 			=> 200,
		'minimumInputLength' 	=> 2,
		'resultsFormat' 		=> '$Title',
		'selectionFormat' 		=> '$Title',
		'placeholder'			=> 'Search...'
	);


	function Field($properties = array()){
		Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
		Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
		Requirements::javascript(SELECT2_MODULE . "/select2/select2.js");
		Requirements::javascript(SELECT2_MODULE . '/javascript/ajaxselect2.init.js');
		Requirements::css(SELECT2_MODULE . "/select2/select2.css");
		return parent::Field($properties);
	}


	public function search($request){
		$list = DataList::create($this->getConfig('classToSearch'));
		
		$params = array();
		$searchFields = $this->getConfig('searchFields');
		foreach($searchFields as $searchField) {
			$name = (strpos($searchField, ':') !== FALSE) ? $searchField : "$searchField:partialMatch";
			$params[$name] = $request->getVar('term');
		}	
		$start = (int)$request->getVar('id') ? (int)$request->getVar('id') * $this->getConfig('resultsLimit') : 0;
		$list = $list->filterAny($params);
		$total = $list->count();
		$results = $list->sort(strtok($searchFields[0], ':'), 'ASC')->limit($this->getConfig('resultsLimit'), $start);
		
		$return = array(
			'list' => array(),
			'total' => $total
		);

		$originalSourceFileComments = Config::inst()->get('SSViewer', 'source_file_comments');
		Config::inst()->update('SSViewer', 'source_file_comments', false);
		foreach($results as $object) {
			$return['list'][] = array(
				'id' => $object->ID,
				'resultsContent' => html_entity_decode(SSViewer::fromString($this->getConfig('resultsFormat'))->process($object)),
				'selectionContent' => SSViewer::fromString($this->getConfig('selectionFormat'))->process($object)
{'fraction_non_alphanumeric': 0.196938542380626, 'fraction_numerical': 0.007767877541695225, 'mean_word_length': 5.457227138643068, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 65, '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': '1275989', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1393, 'n_words': 224}