views:

31

answers:

2

Hello.

I need a simple search form on my Drupal site but I can't figure out the best way to get it done. Basically I have a content type with a couple of different fields and I want my form to search in both the title and the body and then return a list with the title its picture and the stripped body.

I have tried with Views and it works fine and ajaxy except there are two fields - one for the title and one for the body.

Do I make my own module with a little sql and whatever else is necessary or is there a way to get Views to do it for me?

A: 

The solution I used for a similar case sounds strange, but in the global price of preformance/coding/space, it is a great and simple solution.

The solution is here.

in few words:

  • Use computed CCK field to combine all of the fields you want to search on.
  • Write a small AJAX to search on the computed field.
  • Create a view that will show the original fields and not the computed field.

Good luck, Let me know if you need further help.

Shushu
I looked into this solution myself but decided it was sort of a hacky solution. If I combine the two fields with a computed CCK field that means I will have everything in my database twice, right? I have a lot of entries and I don't want my database to grow too much.
theory
True, your database will grow. And true, it is possible to develop your own search solution.The question I ask myself is - what will cost me more. In this certain case I think space will be more less expensive then custom development.I don't think it is a hacky solution. It is the way to be practical.
Shushu
A: 

You can also do a custom search form, which will show your custom results, which can be extracted with your own SQL queries (combining the fields and such).

Are you sure your current search is not already looking in the title and body field??

Ferran Gil
I think my current search is looking in both the title and the body but I tried doing it using the views exposed filters and didn't seem to be able to find a solution. I'm trying to do something like the search and filters on the Apple trailers page (http://trailers.apple.com/) and it is definitely possible and pretty easy - except when I exposed more than one filter (title, body, terms) I got more than one search box. Could you point me to a good guide showing how to do a custom search form?
theory
Ferran Gil