Jump to content

Search DuckDuckGo Next With Google Suggest Completions


Recommended Posts

Just wanted to bubble up a new post to let you know I just updated my DuckDuckGo workflow from over a year ago to support the new (and lovely) DuckDuckGo Next. This is still a mod of David Ferguson's awesome Google Suggest Workflow. The only difference is that it uses DuckDuckGo Next to do the actual search. More details over on the candler blog.

 

Download Google Auto Complete to DDG Next.zip

 

DuckDuckGo Next actually has autocompletions, but I wouldn't know how to get those into the Alfred workflow yet. For now the autocompletions still go through Google Suggest.
 

Here's a vintage screenshot:

 
Screen%20Shot%202013-03-18%20at%207.48.5
 
Enjoy and happy searching!
Link to post

I dug around in the ddg next code and found the url call for its autocomplete results:

https://duckduckgo.com/ac/?q=query

where "query" is whatever you're searching for.

 

Google's autocorrect results are output as xml, and the workflow is set up to parse that.

 

DDG's autocorrect outputs a series of strings in curly braces. Maybe someone with php knowhow can adapt the script so it parses DDG's results intead?

 

Edit: Apparently it's JSON that ddg's autocomplete outputs.

Edited by paulw
Link to post

Okay, I cobbled together something retrieves and parses DuckDuckGo's native search suggestions. Feel free to use it (or improve it) to update your workflow.

require_once('workflows.php');

$wf = new Workflows();
$orig = "{query}";
$json = $wf->request( "https://duckduckgo.com/ac/?q=".urlencode($orig));
$json = utf8_encode($json);
$items = json_decode($json,true);
$int = 1;
foreach($items as $item):
	foreach($item as $suggestion):
		$wf->result( $int.'.'.time(), "$suggestion", "$suggestion", 'Search DuckDuckGo for '.$suggestion, 'icon.png'  );
	endforeach;
endforeach;

$results = $wf->results();
if ( count( $results ) == 0 ):
	$wf->result( 'ddgsuggest', $orig, 'Search DuckDuckGo for '.$orig, 'No suggested matches, search DuckDuckGo for '.$orig, 'icon.png' );
endif;

echo $wf->toxml();
Edited by paulw
Link to post

I made an additional change in my version of the script filter on my machine: I want to be able to search for the original term as entered if I don't like the search suggestions. I would have liked to be able to use a modifier key to do that, but couldn't figure out how, since the original {query} is no longer available and has been replaced by the search suggestions.

 

So I cut out the fallback part of the script (if there are no suggestions) and instead added a first item to the results list that matches the original search term.

require_once('workflows.php');

$wf = new Workflows();
$orig = "{query}";

$wf->result( 'ddgignoresuggest', $orig, 'Search DuckDuckGo for '.$orig, 'Search DuckDuckGo for '.$orig.' or search suggestions below', 'icon.png' );

$json = $wf->request( "https://duckduckgo.com/ac/?q=".urlencode($orig));
$json = utf8_encode($json);
$items = json_decode($json,true);
$int = 1;
foreach($items as $item):
	foreach($item as $suggestion):
		$wf->result( $int.'.'.time(), "$suggestion", "$suggestion", 'Search DuckDuckGo for '.$suggestion, 'icon.png'  );
	endforeach;
endforeach;

echo $wf->toxml();
Link to post
  • 2 months later...

Big thanks to poritsky and paulw! Great workflow!

 

But does autocomplete also work with German Umlauts like ü, ö, ä?

I get results like fÃ1/4r instead of für.

 

It looks like all that's required is to remove this line:

$json = utf8_encode($json);

It doesn't seem like removing it breaks anything.

 

Here's the updated script filter:

require_once('workflows.php');

$wf = new Workflows();
$orig = "{query}";

$wf->result( 'ddgignoresuggest', $orig, 'Search DuckDuckGo for '.$orig, 'Search DuckDuckGo for '.$orig.' or search suggestions below', 'icon.png' );

$json = $wf->request( "https://ac.duckduckgo.com/ac/?q=".urlencode($orig));
$items = json_decode($json,true);
$int = 1;
foreach($items as $item):
	foreach($item as $suggestion):
		$wf->result( $int.'.'.time(), "$suggestion", "$suggestion", 'Search DuckDuckGo for '.$suggestion, 'icon.png'  );
	endforeach;
endforeach;

echo $wf->toxml();
Link to post
  • 1 year later...

I looked into this for my Searchio! workflow.

 

DDG's search suggestion API doesn't support bangs.

 

You might be able to hack something together by parsing the HTML or hacking some unofficial API, but that would be slow and liable to break.

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...