More Search Function Questions

14 posts by 7 authors in: Forums > CMS Builder
Last Post: October 18, 2010   (RSS)

By Mikey - September 12, 2010

Dave
I'm having the same issue as InHouse on one of my web sites:
(1 - My search responses using the 'multisearch' option seem to be case sensitives. Can anyone point me in the direction of making it case insensitive?)

Is there a solution that can be posted in this thread to help those of use having the case sensitive issues with multiSearch.php ? I've used the multiSearch.php on a couple of web sites I've built. On one web site it works perfectly and is not case sensitive... on the other web site it only returns case sensitive results only. The code I've used on both sites is practically identical other than the records it checks during the search, therefore I'm quite certain it's a setting on my server that may be causing the one site to be case sensitive during multiSearch.php queries.

Is there a .htaccess mod rewrite I could use to to make the multiSearch.php be case insensitive or is there something you can suggest to help me make my search engine case insensitive?

The .htaccess I've got loaded now is:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]

I tried adding [NC] to this as seen below, but it didn't help:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [NC,L,QSA]

Hi J,

It shouldn't be case sensitive as it uses the MySQL "LIKE" function which is case-insensitive. If you can send me CMS and FTP login details to dave@interactivetools.com I could check it out for you. (Email, don't post login details to the forum).

As for multisearch, it's fairly limited. If you want to tell me about what you're trying to do via email we can see if it can be easily extended for what you need.

Hope that helps!

Re: [chris] More Search Function Questions

By Mikey - October 15, 2010

Hey Chris,
I'm still not having any luck getting my searchEvents.php page to search the event records case insensitive. I've pasted the code for my page below. Is there something I'm doing wrong that is causing the search to only produce result based on case sensitivity?

Thanks for the help,
Zick

====== begin code =======
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php

require_once "/var/www/hosts/domain.com/httpdocs/cms/lib/viewer_functions.php";

// begin code for search specific page (searchEvents.php) content
list($searchRecords, $searchMetaData) = getRecords(array(
'tableName' => 'search',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$searchRecord = @$searchRecords[0]; // get first record

// show error message if no matching record is found
// if (!$searchRecord) {
// header("HTTP/1.0 404 Not Found");
// print "Record not found!";
// exit;
//}

?>
<?php
// search viewer code to search event records begins
$searchOptions = array();
$searchOptions['keywords'] = @$FORM['q'];
$searchOptions['perPage'] = "10";
$searchOptions['debugSql'] = "0";

$searchTables = array();

$searchTables['events'] = array(
'viewerUrl' => 'eventDetails.php',
'titleField' => 'title',
'summaryField' => 'content',
'searchFields' => array('title','date','content','description','category'),
);

list($searchRows, $searchDetails) = searchMultipleTables($searchTables, $searchOptions);
// search viewer code ends
?>
<?PHP
function maxWords($textOrHtml, $maxWords) {
$text=str_replace("<p>","*P*",$textOrHtml);
$text= str_replace("</p>","*/P*",$text);
$text = strip_tags($text);
$words = preg_split("/\s+/", $text, $maxWords+1);
if (count($words) > $maxWords) { unset($words[$maxWords]); }
$output = join(' ', $words);
$output=str_replace("*P*","<p>",$output);
$output=str_replace("*/P*","</p>",$output);
$output.="...</p>";

return $output;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Title</title>

</head>
<body>

<h1>Search Events</h1>

<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<input type="text" name="q" value="<?php echo htmlspecialchars(@$FORM['q']); ?>" size="50" />
<input type="submit" name="input" value="Search" /><input name="reset" type="button" onclick="parent.location='searchEvents.php'" value="reset" />
<br/>
<br/>
<table border="0" cellpadding="0" cellspacing="0" width="98%">
<tr>
<td><h3> Search results for <b><?php echo htmlspecialchars(@$FORM['q']); ?></b></h3></td>
<td align="right"><p>Results <b><?php echo htmlspecialchars(@$searchDetails['pageResultsStart']); ?></b> to <b><?php echo htmlspecialchars(@$searchDetails['pageResultsEnd']); ?></b> of <b><?php echo htmlspecialchars(@$searchDetails['totalRecords']); ?></b>.</p></td>
</tr>
</table>
<!-- show errors -->
<p><?php if ($searchDetails['invalidPageNum']): ?>
Results page '<?php echo $searchDetails['page']?>' not found, <a href="<?php echo $searchDetails['firstPageLink'] ?>">start over &gt;&gt;</a>.<br/>
<?php elseif ($searchOptions['keywords'] && $searchDetails['noRecordsFound']): ?>
No records matched search query!<br/>
<?php elseif ($searchOptions['keywords'] == ""): ?> </p>
<?php endif ?>

<!-- display results -->
<?php foreach ($searchRows as $record): ?></p>
<h2><a href="<?php echo $record['_link'] ?>"><?php echo $record['_title'] ?></a></h2>
<p><?php if ($record['_summary']): ?>
<?php echo maxWords($record['_summary'], 40); ?></p>
<?php else: ?>
<p>No description available for page.</p>
<?php endif ?>
<h5><a href="<?php echo $record['_link'] ?>"><strong>Read more</strong></a></h5>
<?php endforeach ?>
<!-- /display result -->

<!-- display links -->
<h5><strong>
<?php if ($searchDetails['prevPage']): ?>
<a href="<?php echo $searchDetails['prevPageLink'] ?>">prev</a>
<?php else: ?>
prev
<?php endif ?>
- page <?php echo $searchDetails['page'] ?> of <?php echo $searchDetails['totalPages'] ?> -
<?php if ($searchDetails['nextPage']): ?>
<a href="<?php echo $searchDetails['nextPageLink'] ?>">next </a>
<?php else: ?>
next
<?php endif ?>
</strong></h5>
<!-- /display links -->
</form>

</body>
</html>

====== /end code ========

Hi zickey,

Can you make sure your field list ends with "_keyword"?

For example, the last field in this list is "contact_name":

<input type="text" name="region,primary_community,location,start,description,sponsor,contact_name_keyword" ...

The correct format is:

FIELD,FIELD,FIELD,...,FIELD_keyword

If that doesn't help, please post your <FORM> code and your getRecords() code.

Re: [zick] More Search Function Questions

By Jason - October 18, 2010

Hi Zickey,

Since you're only searching against 1 table, you won't need to use the searchMultipleTables() function. You could try searching like this:

list($resultRecords,$resultMetaData) = getRecords(array(
'tableName' => 'events',
'allowSearch' => false,
'perPage' => 10,
'where' => "LOWER(title) LIKE '%".mysql_escape(strtolower(@$_REQUEST['q']))."%' OR LOWER(date) LIKE '%".mysql_escape(strtolower(@$_REQUEST['q']))."%' OR LOWER(content) LIKE '%".mysql_escape(strtolower(@$_REQUEST['q']))."%' OR LOWER(description) LIKE '%".mysql_escape(strtolower(@$_REQUEST['q']))."%' OR LOWER(category) LIKE '%".mysql_escape(strtolower(@$_REQUEST['q']))."%'",
));


This code will convert everything to lowercase before doing the search.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/