replacing drupal 6 core search with views search

mallet's picture

Hi all

I am trying to replace drupals core search with my own views search. the search in views work but only if you type its exact url would you see the views search. and this is where I am having hard time putting the two together.

I am using the function hook_menu_alter to replace the drupal core search with my views search path. heres the code thats on my custom module file:

<?php
function searchy_perm() {

return array(
'access searchy', 'administer searchy');

}
// function searchy_perm


function searchy_menu_alter(&$callbacks) {
 
// Example - disable the page at node/add
 
$callbacks['search/node']['mynameofview'] = FALSE;

}
?>

Ive been told that my callbacks might be incorrect also on the drupal forums? or if anyone can please give me an example to what I should put in my callback?

-viper

Comments

simplest way to to take your

Scott Reynolds's picture

simplest way to to take your view and configure its path to be 'search/node'. Views handles the menu_alter for you. So it will override the existing search paths

thanks for that piece of

mallet's picture

thanks for that piece of info :)
whats strange is that when you type inside the core search and click search it displays the normal drupal results page. when you type it in again in the drupal result page, it goes to the views search but with no results which you then need to type again on the views search to finally get the result of the page.

so in short, it goes through three search results to get to the views search. have I miss out on a specific option on the views page settings?

-Viper

Ugh. The search block is so

robertDouglass's picture

Ugh. The search block is so horrible. It has a different form id and does "funky stuff". http://api.drupal.org/api/function/search_block/6 (notice that it is search_block_form).

The important thing to remember when debugging this is that $_POST requests always get redirected to $_GET requests (http://api.drupal.org/api/function/search_view/6)

I'm guessing that there is some sort of confusion going on because of the form id.

I can see why this is

mallet's picture

I can see why this is happening from the searchpages.inc file. how do I go about getting the form for my views search to be replaced by the default drupal search blocks? would this require editing the template.php file also?
theres quite few techniques on doing this and I am bit baffled by it. really sorry about this, as this search stuff is really new to me :(

-Viper

Why don't you not display

Scott Reynolds's picture

Why don't you not display the search block and use your views search block.

Meaning, in the views interface create a new block. And put that block in the region you want it in. And then remove the search block :-D

By the way, I'd like to do

fumbling's picture

By the way, I'd like to do this to but I don't know how to disable the search block. I mean, I could hack core, but is there another and better way? Thanks for any instruction on this one.

admin/build/block and remove

Scott Reynolds's picture

admin/build/block and remove the search block from the region....

I must be missing something here cause that is what I meant.

great! got it working and

mallet's picture

great! got it working and looks fab. thanks guys. honestly, I really do appreciate the help and time you taken to help me out :)

-Viper

search code changes

ashiwebi's picture

Is there any patch which add the searching on the basis of sorting of date,title,relevancy

I think you need to go into

mallet's picture

I think you need to go into the views and try adding either: fields or filters and adding the date, title etc and see if that works. My knowledge in views isnt that great but that should work.
theres also the Sort criteria option as well.

best of luck.

-Viper

There isn't a nice way to

Scott Reynolds's picture

There isn't a nice way to expose Sorts. I have gotten away with it in the past by creating several views (in this case three) with the different sorts and then providing links to each one, either in the block or via theming the exposed filter form.

How about using a table??

Gabrieles's picture

Make it an unsorted table and you will have the relevancy as the default, and make it sortable with the date and title fields.
I would usually use that. Are there any cons to this approach??

I'd like to do this too and

Duplika's picture

I'd like to do this too and I can't seem to figure it out. I'm currently using "search/node/%" as the page path. Here are my questions in case someone has the free time to answer them:

  1. Are you using any arguments to replace the research results with Views?
  2. You placed a custom module at the very first post. Is that necessary?
  3. Should I include any filter?

I was used to use views fast search before but since I'm using Drupal 6, I need another solution. Any help is really appreciatted.

Drupal Soul - Drupal Services

Use the exposed filter for

Scott Reynolds's picture

Use the exposed filter for the search. No custom module necessary.

Views Fast Search just used the same filter but instead of creating temporary tables for the search results, it did it using a sub query. Now, in Drupal 6, the search filter will not create temporary tables, it uses a subquery. Essentially, Views fast search was folded into Drupal 6 Core.

So, use the exposed filter for Search.

This doesn't work for me.

2noame's picture

This doesn't work for me. Using search/node/% as the page path results in an Access Denied message whenever I try to use the exposed search block to search for anything.

Just confined to a table

Scott Reynolds's picture

Just confined to a table view style.

http://drupal.org/node/331976

****Me and Drupal :)****
Clickbank IPN - Sell online or create a membership site with the largest affiliate network!
Review Critical - One of my sites

Themed search box

aharown07's picture

I've got a search box built into my theme & like it alot (based on zen classic)... is it possible to make the themed search box point to Views? Or I suppose what I really need to do is figure out how to get a Views filter to display there instead. No clue how to do that.

Search view shows all contents instead of real search result

alyyas's picture

I am using faceted search and it is working fine.
Then i create a search result view and attach it on result page (thesearch/results/%) it will show all content data from my site instead of that search result in a nice table view style.

Here are my questions:
1. i have to use any arguments to replace the research results with Views?
2. Should I include any filter in views?

Search

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: