views:

177

answers:

2

I'm working on a RSS feed where full text search has to be offered - you search from some box, and get the result as a RSS. I've been trying to get node_search and do_search working but I'm missing something... but what?

As far as I can tell, something like $find = node_search('search', 'type:article'); should give me a result containing all matching nodes where the type = 'article'. But how do I specify the keyword/search term?

What am I missing?

A: 

The OpenSearch module exposes search results as RSS, no need to code it yourself.

If you want a specialised form, you can just to a redirect to the OpenSearch result after processing your form.

Addendum: If you really want do do your own, you can use search_data like this:

<?php
$data = search_data('your searchterms here');

This searches nodes (as the default second parameter for search_data), but can also be used to search users and other things that have implemented hook_search.

Also, search_data, belying the name, actually returns the formatted search results. If you want to have the raw search results, you can invoke hook_search directly, or use do_search. Examples:

<?php
$results = module_invoke('node', 'search', 'your searchterms here');
$data = do_search($query, 'node');

The difference being is that invoking the hook gives you a lot more node-related data (since it runs through the node-specific search code, in addtion to the generic do_search (node.module's hook_search implementation calls do_search to get the actual work done)) and a possibly more accurate search, since the node search respects the weights you might have set in the search settings. The tradeoff is a slower search query.

mikl
thanks, but I have to code it, I need this as part of an existing module, all I need to know is, how do I specify the actual search term?
kristian nissen
Alright, I've amended my answer (since formatting is not allowed in comments) with a few details about accessing search data directly :)
mikl
A: 

It should jsut be key:value you can use - and "" also.

hook_search

Phil

Phil Carter
yup, I get that part, but what is the key for the search term?
kristian nissen
its 'key' ! the documentation and naming conventions inuse are pretty poor for Drupal as a rule, search ranks pretty high on the really bad documentation scale.
Phil Carter

related questions