Created
March 28, 2012 18:57
-
-
Save molekilla/2229438 to your computer and use it in GitHub Desktop.
Escuelita de Scala - Parte 4a - typeahead continue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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