Hi folks,
I’ve tried to extend the search provided by AjaxSearch to TVs.
I must certainly be wrong but changing few lines in doSearch function seems to work.
I’m probably wrong cause it seems too easy to be true.
Could you confirm I’m wrong.
I’ve tested a bit and seems to work.
<?php
if ($ajaxSearch) {
$tbl_sc = $table_prefix . "site_content";
$tbl_stc = $table_prefix . "site_tmplvar_contentvalues";//helio
$tbl_dg = $table_prefix . "document_groups";
} else {
$tbl_sc = $modx->dbConfig['dbase'] . "." . $modx->dbConfig['table_prefix'] . "site_content";
$tbl_stc = $modx->dbConfig['dbase'] . "." . $modx->dbConfig['table_prefix'] . "site_tmplvar_contentvalues";//helio
$tbl_dg = $modx->dbConfig['dbase'] . "." . $modx->dbConfig['table_prefix'] . "document_groups";
}
if ($docgrp) {
$tbl_sql = " LEFT JOIN $tbl_stc stc ON sc.id = stc.contentid ";//helio
$tbl_sql .= " LEFT JOIN $tbl_dg dg ON sc.id = dg.document";
$qry_sql = "(ISNULL(dg.document_group) OR dg.document_group IN ($docgrp)) AND ";
} else {
$tbl_sql = " LEFT JOIN $tbl_stc stc ON sc.id = stc.contentid ";//helio
$qry_sql = "sc.privateweb = 0 AND ";
}
if ($searchStyle == 'partial'){
$sql = "SELECT DISTINCT sc.id, sc.pagetitle, sc.description, sc.content ";
$sql .= "FROM $tbl_sc sc" . $tbl_sql . " WHERE ";
if (count($search)>1 && $useAllWords){
foreach ($search as $searchTerm){//helio
$sql .= "(sc.pagetitle LIKE '%$".$searchString."%' OR sc.description LIKE '%$searchString%' OR sc.content LIKE '%$searchTerm%' OR stc.value LIKE '%$searchTerm%') AND ";
// $sql .= "(sc.pagetitle LIKE '%$".$searchString."%' OR sc.description LIKE '%$searchString%' OR sc.content LIKE '%$searchTerm%') AND ";
}
} else {
$sql .= "(sc.pagetitle LIKE '%$searchString%' OR sc.description LIKE '%$searchString%' OR sc.content LIKE '%$searchString%' OR stc.value LIKE '%$searchString%') AND ";
//$sql .= "(sc.pagetitle LIKE '%$searchString%' OR sc.description LIKE '%$searchString%' OR sc.content LIKE '%$searchString%') AND ";
}
$sql .= $qry_sql . "sc.published = 1 AND sc.searchable=1 AND sc.deleted=0;";
} else {
$sql = "SELECT DISTINCT sc.id, sc.pagetitle, sc.description, sc.content ";
$sql .= "FROM $tbl_sc" . $tbl_sql . " sc WHERE ";
if (count($search)>1 && $useAllWords){
foreach ($search as $searchTerm){
//$sql .= "MATCH (sc.pagetitle, sc.longtitle, sc.introtext, sc.description, sc.content) AGAINST ('$searchTerm') AND ";
$sql .= "MATCH (sc.pagetitle, sc.longtitle, sc.introtext, sc.description, sc.content, stc.value) AGAINST ('$searchTerm') AND ";
}
} else {
//$sql .= "MATCH (sc.pagetitle, sc.longtitle, sc.introtext, sc.description, sc.content) AGAINST ('$searchString') AND ";
$sql .= "MATCH (sc.pagetitle, sc.longtitle, sc.introtext, sc.description, sc.content, stc.value) AGAINST ('$searchString') AND ";
}
$sql .= $qry_sql . "sc.published = 1 AND sc.searchable=1 AND sc.deleted=0;";
}
:-)