Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding solr search action, hooking into routes, almost working
- Loading branch information
Dan Simon
committed
Jul 17, 2012
1 parent
7f1e71b
commit 5bdae58
Showing
4 changed files
with
94 additions
and
8 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package controllers | ||
package actions | ||
package resources | ||
|
||
import asset.{AssetFinderDataHolder, FindAction => AssetFindAction} | ||
|
||
import models.{Asset, AssetView, Page, PageParams, Truthy} | ||
import util.SecuritySpecification | ||
import util.plugins.solr._ | ||
|
||
import play.api.data.Form | ||
import play.api.data.Forms._ | ||
import play.api.mvc.Result | ||
|
||
case class SolrFindAction ( | ||
pageParams: PageParams, | ||
query: String, | ||
details: Truthy, | ||
spec: SecuritySpecification, | ||
handler: SecureController | ||
) extends AssetFindAction(pageParams, spec, handler) with AssetResultsAction { | ||
|
||
case class SolrQueryDataHolder(query: CollinsSearchQuery) extends RequestDataHolder | ||
|
||
override def validate(): Either[RequestDataHolder, RequestDataHolder] = (new CollinsQueryParser) | ||
.parseQuery(query) | ||
.right | ||
.flatMap{_.typeCheck} | ||
.fold[Either[RequestDataHolder, RequestDataHolder]]( | ||
error => Left(RequestDataHolder.error400(error)), | ||
expr => Right(SolrQueryDataHolder(CollinsSearchQuery(expr, pageParams))) | ||
) | ||
|
||
override def execute(rd: RequestDataHolder) = rd match { | ||
case SolrQueryDataHolder(query) => { | ||
query.getPage().fold ( | ||
error => handleError(RequestDataHolder.error500(error)), | ||
page => handleSuccess(page, details.isTruthy) | ||
) | ||
} | ||
} | ||
|
||
override protected def handleWebSuccess(p: Page[AssetView], details: Boolean): Result = { | ||
p.size match { | ||
case 0 => | ||
Redirect(app.routes.Resources.index).flashing("message" -> AssetMessages.noMatch) | ||
case 1 => | ||
Status.Redirect(p.items(0).remoteHost.getOrElse("") + app.routes.CookieApi.getAsset(p.items(0).tag)) | ||
case n => | ||
Status.Ok(views.html.asset.list(p)(flash, request)) | ||
} | ||
} | ||
|
||
override def handleWebError(rd: RequestDataHolder): Option[Result] = Some( | ||
Redirect(app.routes.Resources.index).flashing("error" -> rd.toString) | ||
) | ||
|
||
} |
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
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