duckduckgo / zeroclickinfo-spice

DuckDuckGo Instant Answers based on JavaScript (JSON) APIs
https://duckduckhack.com/
Other
548 stars 942 forks source link

RedditSubSearch: Switch to trigger words #1591

Closed moollaza closed 9 years ago

moollaza commented 9 years ago

Seeing as the regex it uses looks for /r/ or r/ (or subreddit) we should be able to use a word trigger because the "words" of a query are not only split on spaces, but also slashes, dashes, periods, and other punctuation.

As a result, triggers startend => "subbredit", "r" followed by a handle that checks the query against our current trigger regex should work in exactly the same way, but it's much more efficient because we're not using a regex trigger.

https://duck.co/ia/view/reddit_sub_search

puskin94 commented 9 years ago

@moollaza I only have one question: How can I check the triggers without a regex if a word trigger has not spaces? r/ pizza and /r/ pizza works because there is a space between the trigger and the query, but r/pizza cannot be triggered because there is no space and the trigger is not recognized. Am I right? I'm playing with this IA but I can't write a working solution ;)

moollaza commented 9 years ago

@puskin94 hmm it looks like there's possibly a bug in the DuckDuckGo library. The triggering does work as expected, which you can see if you turn on the Block Trace debug: DDG_BLOCK_TRACE=1 duckpan query

You'll have to change the IA to simply return $_ in the handle because it doesn't have a remainder (which is the bug and why you likely didn't get a result).

If you switch it to handle query_lc and run the original regex in the handle to ensure we have a properly formatted query, this should work as expected.

jagtalon commented 9 years ago

Fixed by @puskin94