Jump to content

odd search results


Marty Walker
 Share

Recommended Posts

Hi all,

I've had this site running for a while now but the client has just noticed that when they perform a site search on certain terms they're getting no results.

Eg: http://theinfantshome.org.au/search/?q=family+day+care

... which should return results to a number of pages including this one: http://theinfantshome.org.au/our-services/early-education-care/family-day-care/

I'm using the stock standard search template code from the default PW installation (see below), none of the pages I'm searching for are hidden and there's no Access management enabled on the templates.

What's even more odd is if I search for 'family day care' in the PW admin I get no results either yet that page title exists. But if I search for 'family' that page gets returned in the results.

I'm running the latest (non-dev) build too: 2.3.1

Any help really appreciated.

Regards

Marty

<?php

/**
 * Search template
 *
 */

$out = '';

if($q = $sanitizer->selectorValue($input->get->q)) {

	// Send our sanitized query 'q' variable to the whitelist where it will be
	// picked up and echoed in the search box by the head.inc file.
	$input->whitelist('q', $q); 

	// Search the title, body and sidebar fields for our query text.
	// Limit the results to 50 pages. 
	// Exclude results that use the 'admin' template. 
	$matches = $pages->find("title|body|sidebar~=$q, limit=50"); 

	$count = count($matches); 

	if($count) {
		$out .= "<h2>There are $count pages matching your query:</h2>" . 
			"<ul>";

		foreach($matches as $m) {
			$out .= "<li><a href='{$m->url}'>{$m->title}</a><br />{$m->summary}</li>";
		}

		$out .= "</ul>";

	} else {
		$out .= "<h2>Sorry, no results were found.</h2>";
	}
} else {
	$out .= "<p>Please enter a search term in the search box (upper right corner).</p>";
}

// Note that we stored our output in $out before printing it because we wanted to execute
// the search before including the header template. This is because the header template 
// displays the current search query in the search box (via the $input->whitelist) and 
// we wanted to make sure we had that setup before including the header template. 
?>

<?php include('header.inc'); ?>
<body>
<div class="header clearfix">

<?php include('logo.inc'); ?>

<?php include('nav.inc'); ?>

<h2 class="section"><? echo $page->rootParent->get("section_title_custom|title"); ?></h2>

<div class="content-top"><img src="<? echo $config->urls->templates?>images/content-bg.gif" alt="content-bg" width="976" height="11" /></div>
<div class="content clearfix">

<? include('breadcrumbs.inc'); ?>
<div class="article">
<h1>Search results:</h1>
<? echo $out; ?>
</div>

</div>
	
<? include('footer.inc'); ?>

Link to comment
Share on other sites

I realise that Marty and many others fully understand the issues here, but for anyone else with similar problems, here it is in a nutshell...

  • PW selectors use mySQL fulltext indexes (indices? I'm never sure) mostly, as they are very fast. However
  • Fulltext indexes miss out some common words (stopwords) because they are too common to influence search results meaningfully for the most part. And
  • Fulltext indexes ignore words shorter than 4 letters, unless you have enough control of the server to change that default behaviour. (Think VPS or better.) However
  • PW's %= selector operator uses mySQL's LIKE operator, which while slower than a fulltext search, is still very fast (certainly on fewer than several thousand records) and isn't restricted by stopword lists or word length.
  • Like 7
Link to comment
Share on other sites

ProcessWire will automatically remove stop words from a query that's going to use a fulltext index. However, it doesn't know what your MySQL ft_min_word_len might be (minimum indexed word length). So in this case I think the issue is the 3 character word "day", when the ft_min_word_len is 4. Marty in your case I would just change the search operator from "~=" to "%=". Either that, or you could have run a second query that uses "%=" if the first fails to match any results (this would probably be better). 

Link to comment
Share on other sites

  • 2 months later...

I am on a 2.4 site and a search (in the Admin, the built-in Admin search) for Knowable in order to find instances of wrongly spelt Knowledgeable has no hits, even though the word is in a textarea on a published page.

Any ideas why that would fail (I assume it's not a stop word due to length and uncommonness)?

Ditto searching for "wearing your swimsuit" (it's on a page and there's no hits).

[it's as if the default mode is the admin search only searching Page titles perhaps?]

Edited by alanfluff
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...