Search

5 posts by 3 authors in: Forums > CMS Builder
Last Post: December 28, 2012   (RSS)

Hello,

I'd like to know if it's possible to have a search form that can return results for "widget" if "widgets" is typed (and vice versa).

I am finding that people are often searching using a plural word and currently no search results are being returned. However, if users search using the singular word then results are displayed.

I would be grateful for any guidance people can offer.

Thank you,
Greg

Hi Greg,

If your using the get_records function to return your search results, you can use the keywords search field format to return parts of words. You can read more on it here:

http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html

Here is an example of how you might implement it:

===============================================

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('C:/wamp/www/','','../','../../','../../../');
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' search has been set to true.
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'loadUploads' => true,
'allowSearch' => true,
));

?>

=======================================================

<!-- This search form will return any entries which contain the searched word in the title. -->
<form action="?" method="get" >
<input type="text" name="title_keyword" value="" />
<input type="submit" name="submit" value="Search!" />
</form>

<!-- display all/search results -->

<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<h1>Blog - List Page Viewer</h1>
<?php foreach ($blogRecords as $record): ?>
Record Number: <?php echo htmlencode($record['num']) ?><br/>
Title: <?php echo htmlencode($record['title']) ?><br/>
Date: <?php echo date("D, M jS, Y g:i:s a", strtotime($record['date'])) ?><br/><!-- For date formatting codes see: http://www.php.net/date -->
Content: <?php echo $record['content']; ?><br/>
jhgjhg (value): <?php echo $record['jhgjhgjhgjhg'] ?><br/>
jhgjhg (label): <?php echo $record['jhgjhgjhgjhg:label'] ?><br/>
_link : <a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>

<!-- STEP 2a: Display Uploads for field 'uploads' (Paste this anywhere inside STEP2 to display uploads) -->
<!-- Upload Fields: extension, thumbFilePath, isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight, info1, info2, info3, info4, info5 -->
Uploads:
<blockquote>
<?php foreach ($record['uploads'] as $index => $upload): ?>
Upload Url: <?php echo $upload['urlPath'] ?><br/>

<!-- Uploads: Copy the tags from below that you want to use, and erase the ones you don't need.

Thumb Url: <?php echo $upload['thumbUrlPath'] ?><br/><br/>
Download Link: <a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/><br/>

Image Tags:<br/>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>

info1 (Title) : <?php echo htmlencode($upload['info1']) ?><br/>
info2 (Caption) : <?php echo htmlencode($upload['info2']) ?><br/><br/>

Extension: <?php echo $upload['extension'] ?><br/>
isImage: <?php if ($upload['isImage']): ?>Yes<?php else: ?>No<?php endif ?><br/>
hasThumbnail: <?php if ($upload['hasThumbnail']): ?>Yes<?php else: ?>No<?php endif ?><br/>
<hr/>
// end uploads comment tag -->

<?php endforeach ?>
</blockquote>
<!-- STEP2a: /Display Uploads -->

<hr/>
<?php endforeach ?>

===============================

Thanks

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi guys,

Thanks for your messages!

I now see that the problem is not with the search keyword function that I am using. The problem is because there is no mention of "widgets" in my `cms_listings` table, which is the table being searched. All listings are simply labelled as "widget 100" or "widget 200".

"widgets" is however used as a category name, which is stored in a different table and I would like to be able to return all results from the "widgets" category or simply a link to the "widgets" category.

So I guess my next question is how can I have one search textfield that can return results from multiple tables... is that possible? Or is there a workaround you can suggest?

Thanks again,

Greg

Hi Greg,

Do  a search on the forum for multisearch

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php