<commit_before><?
function check($a, $d = 0) { return  !empty($_GET[$a]) || $d ? ' checked' : ''; }
function cite($a) {	return '<i>'.J_ABBR.'</i>, '.($a[0]+J_YEAR).', '.$a[0].' ('.$a[1].'):'.$a[2].'&ndash;'.$a[3]; }
function linkabs($a) { return '/archive/'.$a[0].'/'.$a[1].'/'.$a[2]; }
function linkpdf($a) { return '/pdf/'.$a[0].'/'.$a[1].'/'.$a[0].'.0'.$a[1].'.'.str_pad($a[2],3,0,STR_PAD_LEFT).'.pdf'; }
function linkedt($a) { return '<span class="rht"><a href="/newabs?vol='.$a[0].'&pg='.$a[2].'">Edit</a></span>'; }
function plural($n, $a) { return '<div>'.$n.' '.$a.($n > 1 ? 's' : '').'</div>'; }
function linker($a, $n = '', $x = '') {
	if(is_array($a)) {
		$a = $a[0];
		if(substr($a,10,7) == 'doi.org') $x = ' class="xref"';
	}
	if(!$n && !$x) $n = $a;
	return $a ? '<a href="'.$a.'"'.$x.'>'.$n.'</a>' : '';
}
function humansize($bytes, $decimals = 2) {
  $sz = 'BKMGTP';
  $factor = floor((strlen($bytes) - 1) / 3);
  if(!(strlen($bytes)%2)) $decimals = 0;
  return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
require_once(INC_DIR.'dbconn.php');
/*?>
		<a href="#add">+ Add new abstract</a>
<?
include 'newabs.php';
*/
$col = 'vol, issue';
$group = 'GROUP BY '.$col;
$query = 'SELECT %s FROM '.TBL_CON.' %s %s';
$ccol = 'vol,issue,start_page,end_page,section,doi,title,author,pdf';
$totrow = 0;
$subj = $db->getAll();
$cond = array();
$xtra = false;

if(isset($_GET['vol']) && $_GET['vol']*1) {
	$cond[] = 'vol = '.$_GET['vol'];
	if(isset($_GET['issue']) && $_GET['issue']*1) {
		$col = $ccol;
		$cond[] = 'issue = '.$_GET['issue'];
		$group = '';
		if(isset($_GET['start_page']) && $_GET['start_page']*1) {
			$col = '*';
			$cond[] = 'start_page = '.$_GET['start_page'];
		}
	}
} else {
	if(!empty($_GET['sec'])) {
		$sec = $_GET['sec'] * 1;
		$keywords = $qval = '';

		if(!empty($_GET['q'])) {
			$qval = ' value="'.$_GET['q'].'"';
			$keywords = implode(' +', preg_split('/\W+/', $_GET['q'], 0, PREG_SPLIT_NO_EMPTY));
		}

		$idx = array(
			'abs' => 'title,author,inst,abstract,keywords',
			'refs' => 'refs'
		);

		foreach($idx as $k => $val)
			if(isset($_GET[$k])) {
				if($sec) $cond['sec'] = "section = ".$sec;
				if($keywords) $cond['kw'] = "MATCH($val) AGAINST ('+".$keywords."' IN BOOLEAN MODE)";
				$cfg[] = "SELECT $ccol FROM ".TBL_CON.($cond ? ' WHERE ' : '').implode(' AND ', $cond);
			}
		if(isset($cfg)) {
			$query = implode(' UNION ',$cfg);
			$xtra = true;
		}
	} ?>
		<div class="search">
			<form action="archive" method="get">
				<div class="full"><input type="text" name="q" placeholder="Search for keywords..."<?=$qval?>></div>
				<div><label class="btn" title="Includes: Title, Author, Institution, Abstract, Keywords"><input type="checkbox" name="abs"<?=check('abs',empty($_GET))?>><span>Content</span></label></div>
				<div><label class="btn"><input type="checkbox" name="refs"<?=check('refs')?>><span>References</span></label></div>
				<div><select name="sec" id="ignore">
					<option selected>All sections</option>
					<? foreach($subj as $k => $v) {
						$sel = $sec && $sec === $k ? ' selected' : '';
						echo '<option value="'.$k.'"'.$sel.'>'.$v.'</option>';
					} ?>
				</select></div>
				<div><button class="btn brd">Search</button></div>
			</form>
		</div>
<?
}
$cond = implode(' AND ', $cond);<commit_msg>Improved search logic<commit_after><?
function check($a, $d = 0) { return  !empty($_GET[$a]) || $d ? ' checked' : ''; }
function cite($a) {	return '<i>'.J_ABBR.'</i>, '.($a[0]+J_YEAR).', '.$a[0].' ('.$a[1].'):'.$a[2].'&ndash;'.$a[3]; }
function linkabs($a) { return '/archive/'.$a[0].'/'.$a[1].'/'.$a[2]; }
function linkpdf($a) { return '/pdf/'.$a[0].'/'.$a[1].'/'.$a[0].'.0'.$a[1].'.'.str_pad($a[2],3,0,STR_PAD_LEFT).'.pdf'; }
function linkedt($a) { return '<span class="rht"><a href="/newabs?vol='.$a[0].'&pg='.$a[2].'">Edit</a></span>'; }
function plural($n, $a) { return '<div>'.$n.' '.$a.($n > 1 ? 's' : '').'</div>'; }
function linker($a, $n = '', $x = '') {
	if(is_array($a)) {
		$a = $a[0];
		if(substr($a,10,7) == 'doi.org') $x = ' class="xref"';
	}
	if(!$n && !$x) $n = $a;
	return $a ? '<a href="'.$a.'"'.$x.'>'.$n.'</a>' : '';
}
function humansize($bytes, $decimals = 2) {
  $sz = 'BKMGTP';
  $factor = floor((strlen($bytes) - 1) / 3);
  if(!(strlen($bytes)%2)) $decimals = 0;
  return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
require_once(INC_DIR.'dbconn.php');
/*?>
		<a href="#add">+ Add new abstract</a>
<?
include 'newabs.php';
*/
$col = 'vol, issue';
$group = 'GROUP BY '.$col;
$query = 'SELECT %s FROM '.TBL_CON.' %s %s';
$ccol = 'vol,issue,start_page,end_page,section,doi,title,author,pdf';
$totrow = 0;
$subj = $db->getAll();
$cond = array();
$xtra = false;

if(isset($_GET['vol']) && $_GET['vol']*1) {
	$cond[] = 'vol = '.$_GET['vol'];
	if(isset($_GET['issue']) && $_GET['issue']*1) {
		$col = $ccol;
		$cond[] = 'issue = '.$_GET['issue'];
		$group = '';
		if(isset($_GET['start_page']) && $_GET['start_page']*1) {
			$col = '*';
			$cond[] = 'start_page = '.$_GET['start_page'];
		}
	}
} else {
	if(!empty($_GET['q']) || !empty($_GET['sec'])) {
		$keywords = $qval = $sec = '';
		$idx = array(
			'abs' => 'title,author,inst,abstract,keywords',
			'refs' => 'refs'
		);

		if(!empty($_GET['sec'])) $sec = $_GET['sec'] * 1;
		if(!empty($_GET['q'])) {
			$qval = ' value="'.$_GET['q'].'"';
			$keywords = implode(' +', preg_split('/\W+/', $_GET['q'], 0, PREG_SPLIT_NO_EMPTY));
		}

		if($sec) $cond[] = "section = ".$sec;
		if($keywords) {
			foreach($idx as $k => $val)
				if(isset($_GET[$k]))
					$cmd[$k] = $val;
		} else $cmd = array(0);
		if(!isset($cmd)) $cmd = $idx;

		foreach($cmd as $k => $val) {
			if($val) $cond['kw'] = "MATCH($val) AGAINST ('+".$keywords."' IN BOOLEAN MODE)";
			$cmd[$k] = "SELECT $ccol FROM ".TBL_CON.($cond ? ' WHERE ' : '').implode(' AND ', $cond);
		}

		$query = implode(' UNION ',$cmd);
		$xtra = true;
	} ?>
		<div class="search">
			<form action="archive" method="get">
				<div class="full"><input type="text" name="q" placeholder="Search for keywords..."<?=$qval?>></div>
				<div><label class="btn" title="Includes: Title, Author, Institution, Abstract, Keywords"><input type="checkbox" name="abs"<?=check('abs',empty($_GET))?>><span>Content</span></label></div>
				<div><label class="btn"><input type="checkbox" name="refs"<?=check('refs')?>><span>References</span></label></div>
				<div><select name="sec" id="ignore">
					<option selected>All sections</option>
					<? foreach($subj as $k => $v) {
						$sel = $sec && $sec === $k ? ' selected' : '';
						echo '<option value="'.$k.'"'.$sel.'>'.$v.'</option>';
					} ?>
				</select></div>
				<div><button class="btn brd">Search</button></div>
			</form>
		</div>
<?
}
$cond = implode(' AND ', $cond);
{'fraction_non_alphanumeric': 0.3157894736842105, 'fraction_numerical': 0.011679479597871082, 'mean_word_length': 4.191864927091328, 'pattern_counts': {'":': 0, '<': 107, '<?xml version=': 0, '>': 118, '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': '2049367', 'n_tokens_mistral': 3019, 'n_tokens_neox': 2779, 'n_words': 490}