I'd like to run a search programmatically but I've had trouble finding good instructions.
I know that there are several (simple) ways of running a search using php:
1. $results = do_search($searchterms, 'node')
2. $results = module_invoke('node', 'search', 'search', $searchterms);
3. $results = node_search('search', $searchterms);
I don't think #2 or #3 are suitable, and from what I've read #1 is the way to go, but there are many inputs to do_search() and I haven't found any good explanations.
Here are my two questions:
1. Running a simple search using do_search()
$result = do_search($terms, 'node');
print_r($result);gives results that look like this:
[0] => stdClass Object
(
[type] => node
[sid] => 319
[score] => 0.99999999999774
)
And I would be fine with this, but, I have no idea how to get the nid from the sid!.
(I believe sid stands for search index id.) Any ideas on how to do this?
2. How can I filter do_search() by node type, such as only return results that are of node type = story, for example?
I've found some stuff online about do_search, but it wasn't very detailed:
http://stackoverflow.com/questions/963972/drupal-node-seach
Drupal's Search Framework: The execution of a search
http://acquia.com/blog/drupals-search-framework-execution-search
http://coder1.com/category/tags/drupal-dosearch
-how to remove the default limit of 10 results from do_search
Any help would be greatly appreciated.
Comments
Subscribing, I was also
Subscribing, I was also curious abt this.
--updated
Just FYI with this, i finally create my own do_search function which replace this code
$result = pager_query("$select $sort_parameters", 10, 0, $count_select, $arguments);with this one:
$result = db_query($select.' '.$sort_parameters, $arguments);It works for me though.