We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11975
    • 2,542 Posts
    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;";
        }
    
    


    :-)
      Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
      • 18397
      • 3,250 Posts
      I think it should be noted that this will not search the output values of the TVs since their widgets would not be applied. Thus, if you have a dropdown that has the options 1=foo;2=cheese you would only be searching for 1 and 2 not foo and cheese.
        • 11975
        • 2,542 Posts
        You’re right Mark
        But it’s a short term solution
        I thought I could combine ajaxsearch and tvExplorer.

        :-)
          Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
          • 25663 MODX Staff
          • 12,272 Posts
          As a partial fix, that seems really like a good start! So what all would this search... If it will get Rich Text fields, we’re in very good shape for starters. smiley
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me