Skip to content

Instantly share code, notes, and snippets.

@molekilla
Created March 28, 2012 18:57
Show Gist options
  • Save molekilla/2229438 to your computer and use it in GitHub Desktop.
Save molekilla/2229438 to your computer and use it in GitHub Desktop.
Escuelita de Scala - Parte 4a - typeahead continue
// RegPubServices
class RegPubServices extends SearchService with DataModelService {
def searchTypeahead(query:String):JsValue = {
val hits = typeahead(query)
val companyNames = hits.map( hit => (hit \\ "fields").map( h => Map("item" -> h \ "nombre"))).flatten
// RM: Alternativamente, para no usar Underscore para crear un array
// val companyNames = hits.map( hit => (hit \\ "fields").map( h => h \ "nombre")).flatten
Json.toJson(companyNames)
}
}
// controller
object Application extends Controller {
def typeahead(searchText:String) = Action {
val searchResults = RegPubServices().searchTypeahead(searchText)
Ok(searchResults)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment