I've searched extensively and found a variety of references to this or that, but what's the definitive way to implement a custom node search?

First, some quick background. I have created a custom node module, which consists of a handful of fields. Everything works as it should.

I now need to introduce a custom search form with search results limited to the one specific node type. The form will appear in a block and be universally accessible throughout the site. This is one of the core features of the site.

I know how to do this directly by constructing a SQL query using the various form values. However this seems inefficient as it bypasses the Drupal index.

I've also seen ways to filter the recordset while outputting the results. This seems even more inefficient.

hook_search() is not suitable. I'm not looking to extend the main search (or advanced search), but create a completely separate search interface.

Worst case, I will implement the aforementioned direct approach, but I would like to know if there is a more Drupal-compliant method.

All comments/suggestions appreciated.

Comments

vm’s picture

Have you investigated the views.module ?

johnhanley’s picture

I've used views.module for lists and such, but I'm not aware of a way to create a search form in a block and output the results in the content column. Needless to say that would be a pretty sweet and easy solution. Please enlighten me if so. :-)

vm’s picture

I seem to recall a discussion where it was stated that views could manage something of this nature with arguments, though I could be totally off base. I've not even stuck my toe into views w/ arguments to be able to enlighten you on this specific subject. Wish I could.

johnhanley’s picture

I sincerely appreciate your input.

I haven't used views w/arguments either, but isn't it essentially for passing values as URI segments?

Returning to my original question, what's the best way to implement a custom search form without circumventing Drupal? Maybe the answer is "there's not." I know how to do this programmatically, but I always strive to conform to Drupal methodology and "best practices" whenever possible.

I already have a custom search form block. I just need to write a custom callback function to execute the query and output the recordset results. I will probably go this route unless someone has a better and/or more compliant idea.

hollybeary’s picture

Did you ever get this working? If so, would you mind sharing? I'm currently looking for this functionality on a site I'm working on and have been banging my head against a wall all day.

www.digett.com - work
www.haleystar.com - personal

johnhanley’s picture

I ended up creating a custom search block. Check out the left-hand "Search for Plants" block here: http://plantlifeonline.net

I used session variables to remember the user's selections and a custom theme for the search results page.

I'm still convinced there's a more integrated way to go about this, but the budget for this particular project didn't provide much time for exploration.

-------------------------------------------------------

"If you don't read the newspaper you are uninformed;
if you do read the newspaper you are misinformed."
-- Mark Twain

gauravkhambhala’s picture

hi Bacteria Man,

I ended up creating a custom search block. Check out the left-hand "Search for Plants" block here: http://plantlifeonline.net

can you share the code with us for our reference ?

That would be very useful.

Its very urgent.

Thanks.

johnhanley’s picture

Sorry, but the code is owned by the client and not intended for public consumption.

That said it's a proprietary implementation using the API and probably wouldn't help you much.

-------------------------------------------------------

"If you don't read the newspaper you are uninformed;
if you do read the newspaper you are misinformed."
-- Mark Twain

vm’s picture

you can do the same with views.module and exposed filters.

johnhanley’s picture

Views w/ exposed filters would probably get you 80% of the way there, but at the time the other 20% mandated a custom solution.

The project is over 1 1/2 years old and I would probably do the whole thing differently now-a-days. That said, I'm still satisfied with the outcome.

-------------------------------------------------------

"If you don't read the newspaper you are uninformed;
if you do read the newspaper you are misinformed."
-- Mark Twain