Combine two fields for search engine results

3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 10, 2013   (RSS)

By Mikey - January 9, 2013

Anyone have some suggestions on the topic of joining two fields for the search engine?

By gregThomas - January 10, 2013 - edited: January 10, 2013

Hi Zack, 

Sorry for the delay in reply.

I think the easiest solution would be to have another field in your section that stores the full item number code, and then just include this in the search term. You could create either a cron job, or if you hav experience of plugins you could create one to combine items num value and product letters into the field, or get the user to manually add them when they create the each record. 

You could also try creating some code to detect when a user has entered a word that is five letters long (assuming the product number is always that long), gets any numbers from the word and then carry out a search for a record with that num value (as the num value will always be unique).  If you used this method, you wouldn't be able to use the default search functionality built into CMS Builder, and would have to customise it slightly. I've done some local testing, and this method seems to work:


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('W:/g/greg.com/htdocs/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }


// load records from 'blog'
list($results, $resultMeta) = getRecords(array(
'tableName' => 'sectionName',
'loadUploads' => false,
'allowSearch' => true,
));

//Get the search term, and explode the string into an array of words
$stringArray = explode(' ', $_REQUEST['title,content,prefix_number,num,summary_keyword']);
//This array contains all of the searched items
$intArray = array();

foreach($stringArray as $word){
//If the word is 5 letters long
if(strlen($word) == 5){
//filter out any letters in contains and store it in the int array
$intArray[] = filter_var($word, FILTER_SANITIZE_NUMBER_INT);
}
}

foreach($intArray as $int){
//check if there are any entries in the section with that int num value
$tempItem = mysql_get('sectionName',$int);
if($tempItem){
$results[] = $tempItem;
}

}

You would need to modify the code so that it uses the correct secion names, and search term.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com