This should be a really easy one for you guys.

I'm trying to modify i404.module to work with trip_search.

I've swapped out

    $results = search_data($keys);

and replaced with

    $results = trip_search_get($keys);

but I get this error:

Missing argument 2 for trip_search_get()

I've tried inserting ('node', $keys), ('basic', $keys), etc which cures the error report, but I'm still not getting any search results ...

what should the first argument be? (or am I using the wrong function altogether?)

any suggestions? please?

Comments

JohnG-1’s picture

apologies for the bump, but surely this seems like a straight forward question which should have a very easy answer ... please could someone take a moment to point me in the right direction?

nedjo’s picture

trip_search_get expects keys that have been parsed into an array. You need to first pass your keys through trip_search_parsed(). If you're dealing with node data, try:


$parsed_keys = trip_search_parse($keys);
$find = trip_search_get('node', $parsed_keys);
if (variable_get('trip_search_rank_results', 1)) {
  $results = trip_search_rank_results($find, $parsed_keys);
}
else {
  $results = $find;
}

But the results array will differ from what you get from core search, and will need different handling.

JohnG-1’s picture

Title: calling trip_search_get() - missing argument - please help » ii404 with trip_search - please help
Priority: Critical » Normal

thanks nedjo - much appreciated.

hmm see what you mean about handling the $results ... not as easy as I thought :(

this is the module I'm trying to modify, with your code added:

// Derived from i404.module by Steven Wittens at http://drupal.org/node/12668
function ii404_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Perform a search when a page is not found.');
  }
}
function ii404_menu() {
  $items[] = array('path' => 'ii404',
    'title' => t('Page not found'),
    'callback' => 'ii404_page',
    'access' => 1,
    'type' => MENU_CALLBACK);
  return $items;
}
function ii404_page() {
  drupal_set_title(t("Page not found"));
  // These are words that should be ignored in the URL
  $no = array("dump", "zip", "avi", "a");
  $uri = $_SERVER['SERVER_PROTOCOL'];
  $uri = strtolower(substr($uri, 0, strpos($uri, '/')));
  $uri .= "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  global $base_url;
  $uri = substr($uri, strlen($base_url) + 1);
  $uri = urldecode($uri);
  $output = t("<p>The page you requested, $base_url/$uri, was not found.</p>");
  $keys = split("[^A-Za-z]+", $uri);
  $keys = array_diff($keys, $no);
  $keys = trim(implode(" ", $keys));

  if ($keys) {
    $parsed_keys = trip_search_parse($keys);
    $find = trip_search_get('node', $parsed_keys);
      if (variable_get('trip_search_rank_results', 1)) {
       $results = trip_search_rank_results($find, $parsed_keys);
      }
      else {
       $results = $find;
      }
      if ($results) {
      $output .= t("<p>For your convenience, a search was performed using the query '<i>%keys</i>':</p>", array("%keys" => $keys));
      $output .= $results;
      }
      else {
      $output .= t("<p>A search was performed for '<i>%keys</i>', but nothing was found.</p>", array("%keys" => $keys));
      }
  }
  print theme("page", $output);
}

as it stands, $results just comes through as the word 'Array' in the html.

I guess I would need to rip some code from the trip_search.module ... but that appears - at a first glance - to be quite extensive ....

I'm wondering if it would be easier to redirect the 'page not found' $keys to trip_search via a url and simply return a standard trip_search results page ... ?

any suggestions very much welcome.

joel_guesclin’s picture

I'm interested in this - is it still active? I'm closing all requests raised on the 4.6 version since I don't intend to continue maintaining this. But would be interested in collaborating for 4.7

JohnG-1’s picture

I think the function of the ii404 module is a very good one but I have sadly been unable to get it to work with 4.6 Trip Search.

I would like to keep it open in the hope that someday someone clever will come along and waive their magic wand at it .... :)

Personally I've been putting off the upgrade to Drupal 4.7 yet but it seems that the increasingly unavoidable due lack of support for 4.6.

mindless’s picture

To use the above code you'd need to change $output .= $results; into a foreach loop on $results. A simpler solution might be for ii404.module to show a simple page with some informative text and a link to /trip_search?keys=.... Or even auto-redirect to that page after 5 seconds or something. Let us know if it's ok to close this request now, thanks.

JohnG-1’s picture

@ mindless : Thank you for the suggestion. As you no doubt realise this is a very old issue so I'm not running anything currently that would benefit. I do still like the feature and I will try out your suggestion when time permits. Please feel free to close this issue.

Many thanks,
JohnG

mindless’s picture

Status: Active » Closed (fixed)