Search

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

By gversion - December 20, 2012

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

By gregThomas - December 21, 2012

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

By gkornbluth - December 24, 2012

Hi Gregs,

Unless I've missed something, using the example you gave, if "widget" is entered,  the search code will return any title that contains the word "widget", so it will return records with things like xwidget and widgets and abcwidgetxyz in the title.

However, if "widgets" is entered as the search term, none of the above will be returned because none of them contains the word "widgets" (plural), which is only answers half of the question.

I saw suggestions for implementing the "like" function with wildcards, but I'm not sure how to do that and think it would cause other issues.

Not all words are pluralized by adding an (s) to the end of them ( party, parties) and simple words like "car" or "cars" might generate many unwanted results that contain the words car or cars.

There might have to be grammatical rules about lengths and ending S letters to sort things out, but even then, not all queries would necessarily be returned as desired.

Just my thoughts...

Best,

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

By gkornbluth - December 28, 2012

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