I’m working on a Drupal Project and I currently have to deal with the Fact that the in-build Search Engine (finder) doesn’t find jack squat. There are some Modules that use Lucene, and of course if you have the Time to walk that extra Mile – good for you! Buuut, in my case i just wanted an fast and easy Way to get some relevant Search Results in case Finder fails to deliver (which it does more often then it does not).
And, quite honestly, I always wanted a reason to play with Yahoo BOSS (google offers something alike but for a (much higher) price). So basically what i did was:
- if finder didn’t return a result i made a Request @ BOSS
- then check the results for matches in the url_alias Table of Drupal (this will come in handy later, but also vital in the matter that you dont want to only spit out tag pages and so on)
- get everything related to nodes (the src would most likely be something like “node/12121″)
- Grep the ID and get the Node with all its related content (see, i say it would come in handy) to display
The Code could look something like this:
$search = 'http://boss.yahooapis.com/ysearch/web/v1/'.urlencode(arg(1)).'%20site:www.example.com?format=xml&appid=MYAPIKEXY&count=20&lang=de';
$xml = simplexml_load_file($search,'SimpleXMLElement', LIBXML_NOCDATA);
foreach($xml->resultset_web->result as $result){?>
<?php
$select = 'SELECT src FROM url_alias where dst = "'.str_replace('http://www.sparwelt.de/','',$result->url).'"';
$foo = db_query($select);
$bar = db_fetch_object($foo);
if(preg_match('#^node/([\d]+)#',$bar->src,$matchid)){
$node = node_load($matchid[1]);?>
<h1>
<a title="<?= $node->title ?>" href="/<?= $node->path ?>"><?= $node->title ?></a>
</h1>
<p>
<?php
if(strlen($node->teaser) > 1){
print $node->teaser;
}else{
print $result->abstract;
}?>
</p>
<?php }
}?>
note: you need to be a registered developer @ yahoo in order to get a BOSS API Key you can do that here
About the Query string, its quite simple:
http://boss.yahooapis.com/ysearch/web/v1/’.urlencode(arg(1)).’%20site:www.example.com?format=xml&appid=MYAPIKEXY&count=20&lang=de
arg(1) gets, in my case, the original finder query string, site:www.example.com tells yahoo only to look on this domain the rest should be clear, and everything is well documented.
