Skip to content

Instantly share code, notes, and snippets.

@cpdean
Created December 3, 2013 03:03
Show Gist options
  • Save cpdean/7763254 to your computer and use it in GitHub Desktop.
Save cpdean/7763254 to your computer and use it in GitHub Desktop.
Getting keywords out of a search
import com.example.util.Codec
import com.example.storm.bolts.IntervalBolt
import com.github.theon.uri.Uri.parseUri
class SomeBolt (serializer:Serializer, ticksBeforeFlush: Int, bufferLimit: Int)
extends IntervalBolt(ticksBeforeFlush) with Codec{
def bufferOffInterval(input: Tuple) = ???
def onInterval() = ???
override def declareOutputFields(declarer:OutputFieldsDeclarer) = ???
def extractKeywords(category: String, url: String) : List[String] = {
val query_key = if (url.contains("http://search.yahoo.com/")) "p" else "q"
if (category == "search")
parseUri(url).query.params.getOrElse(query_key, List()).flatMap(x => x.decodeUrl.split(" "))
else List()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment