Jump to content

I can't get search to search to search to search :(


OrganizedFellow
 Share

Recommended Posts

That title has the worst run on sentence, eh?

When I installed PW, I opted for the new option of installing with a BLANK profile. It's been great so far.

But I can't figure out how to get my search searching?!

From another fresh installation (2.5.3), I copied the contents of 'search.php' into my own 'search.php' file. Added my included header and footer. Then one by one, I copied every setting for the template and page from the other installation to my own. Even copied exactly how the template had the search form.

Every search result is a blank page.

Nothing is outputted.

Link to comment
Share on other sites

Have the same issue. Is this the best solution?

Don't know.

I still can't get it working. I have no idea WHY NOT.

I have duplicated the template file from another fresh installation. Recreated the search page with that template file. It doesn't work.

Makes me think I am missing a crucial step or something important.

Link to comment
Share on other sites

  • 2 weeks later...

Dear all

the solution I have post always worked since then but perhaps because I have to deal mainly with non-latin characters (greek alphabet).

In your case you should consider trying something like this

$selector = "title|body*=$q, limit=50";

please inform me on any solution and I ll keep on searching the subject....but to be honest also on latin search terms I get results with my initial proposal...but yes check this above

Link to comment
Share on other sites

FIND BELLOW THE FUNCTIONING AND IMPORTANT PART OF THE CODE


<?php

// look for a GET variable named 'q' and sanitize it
$q = $sanitizer->text($input->get->q); 

// did $q have anything in it?
if($q) { 
  // Send our sanitized query 'q' variable to the whitelist where it will be
  // picked up and echoed in the search box by _main.php file. Now we could just use
  // another variable initialized in _init.php for this, but it's a best practice
  // to use this whitelist since it can be read by other modules. That becomes 
  // valuable when it comes to things like pagination. 
  $input->whitelist('q', $q); 

  // Sanitize for placement within a selector string. This is important for any 
  // values that you plan to bundle in a selector string like we are doing here.
  $q = $sanitizer->selectorValue($q); 

  // Search the title and body fields for our query text.
  // Limit the results to 50 pages. 
  $selector = "title|body%=$q, limit=50"; 

  // If user has access to admin pages, lets exclude them from the search results.
  // Note that 2 is the ID of the admin page, so this excludes all results that have
  // that page as one of the parents/ancestors. This isn't necessary if the user 
  // doesn't have access to view admin pages. So it's not technically necessary to
  // have this here, but we thought it might be a good way to introduce has_parent.
  if($user->isLoggedin()) $selector .= ", has_parent!=2"; 

  // Find pages that match the selector
  $matches = $pages->find($selector); // did we find any matches?
  if($matches->count) {
    // yes we did
    $content = "<h2>Found $matches->count pages matching your search criteria:</h2>";
    // we'll use our renderNav function (in _func.php) to render the navigation
    $content .= renderNav($matches, 0, 'summary'); 
  } else {
    // we didn't find any
    $content = "<h2>No results found.</h2>";
  }

} else {
  // no search terms provided
  $content = "<h2>Please enter a search term in the search box (upper right corner)</h2>";
}
Link to comment
Share on other sites

  • 1 month later...

ok.

So I've pulled ALL my hair out, again. I still can't get my search working.

I've installed a fresh PW. Copied over the search.php file from the new one to my old one. Double checked the same settings are in the template in the admin side.

I am my end here and don't know what else to do!?

It shouldn't be this hard to get search to search.

Link to comment
Share on other sites

From what I know, you need to have the correct fields you want to search on listed in the search criteria to be successful.

I believe the default criteria in search.php for the site-default profile is:

$selector = "title|body~=$q, limit=50"; 

This works great if you are only searching for words in the Title or Body fields.  

However, If you have any other fields that you want to search on, they need to be added to the search criteria.

$selector = "title|requestor_name|requestor_comments|summary|body~=$q, limit=50"; 

When I first started with PW, I didn't understand this and hence could never get the search results I was looking for.  One day the light went on and I haven't had a problem with searching since.

I don't know if this is the issue that you are having, however  I just thought I would mention it as the default search file works like a charm.

  • Like 1
Link to comment
Share on other sites

I believe the default criteria in search.php for the site-default profile is:

$selector = "title|body~=$q, limit=50"; 

That is exactly what I have, since I am using the default search.php file from a fresh install :(

could it be a server issue? I had a problem with a server blocking certain combinations of words, it was really strange; turned out to be a mod security issue..

Server issue?

Not likely. I am using the exact identical setup on DigitalOcean as another one of my sites.

Link to comment
Share on other sites

Can you please answer the following:

  • What is the structure of your site?
  • Describe what fields you are searching on?
  • Give a few examples of situations where the search fails.
  • Are you able to get any search results at all?
  • What program you are saving your edited copy of the search.php file in?
  • Versions of PHP, MySQL and PW.  
  • Is this a Local install or an online instance?
  • Platform where you are having this problem.
  • Have you tested this on any other platform?
  • Have you tested this on any other install besides the Blank profile?
  • It would also be informative if you can state in what file are you calling the search form?

In the site default profile, the search form is listed as

<form class='search' action='<?php echo $pages->get('template=search')->url; ?>' method='get'>
		<input type='text' name='q' placeholder='Search' value='<?php echo $sanitizer->entities($input->whitelist('q')); ?>' />
		<button type='submit' name='submit'>Search</button>
	</form>

in the _main.php file.  Have you used the same form syntax to call up the search in your install?  If not, could you please list your code.

I know these are a lot of questions, however answering them will help someone to help you find a solution to your problem.

Best Regards,

Charles

  • Like 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...