Jump to content
poritsky

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!

Share this post


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

Share this post


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

Share this post


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();

Share this post


Link to post

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.

Share this post


Link to post

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();

Share this post


Link to post

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.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...