16
16
17
17
package de .upb .cs .swt .delphi .cli .commands
18
18
19
-
20
19
import java .util .concurrent .TimeUnit
21
20
22
21
import akka .actor .ActorSystem
@@ -34,7 +33,7 @@ import spray.json.DefaultJsonProtocol
34
33
35
34
import scala .concurrent .duration ._
36
35
import scala .concurrent .{Await , Future }
37
- import scala .util .Failure
36
+ import scala .util .{ Failure , Success }
38
37
39
38
object SearchCommand extends Command with SprayJsonSupport with DefaultJsonProtocol {
40
39
/**
@@ -50,8 +49,8 @@ object SearchCommand extends Command with SprayJsonSupport with DefaultJsonProto
50
49
51
50
information(config)(s " Searching for artifacts matching ${'"' }$query${'"' }. " )
52
51
val start = System .nanoTime()
53
- implicit val queryFormat = jsonFormat2(Query )
54
52
53
+ implicit val queryFormat = jsonFormat2(Query )
55
54
val baseUri = Uri (config.server)
56
55
val prettyParam = Map (" pretty" -> " " )
57
56
val searchUri = baseUri.withPath(baseUri.path + " /search" ).withQuery(akka.http.scaladsl.model.Uri .Query (prettyParam))
@@ -79,33 +78,36 @@ object SearchCommand extends Command with SprayJsonSupport with DefaultJsonProto
79
78
if (config.raw || result.equals(" " )) {
80
79
reportResult(config)(result)
81
80
} else {
82
-
83
81
val unmarshalledFuture = Unmarshal (result).to[List [SearchResult ]]
84
82
85
- unmarshalledFuture.onComplete {
83
+ val processFuture = unmarshalledFuture.transform {
84
+ case Success (unmarshalled) => {
85
+ processResults(config, unmarshalled, took)
86
+ Success (unmarshalled)
87
+ }
86
88
case Failure (e) => {
87
89
error(config)(result)
90
+ Failure (e)
88
91
}
89
- case _ =>
90
92
}
93
+ }
94
+ }
91
95
92
- val unmarshalled = Await .result(unmarshalledFuture, Duration .Inf )
93
- val capMessage = {
94
- config.limit match {
95
- case Some (limit) if (limit <= unmarshalled.size)
96
- => s " Results may be capped by result limit set to $limit. "
97
- case None if (unmarshalled.size >= 50 )
98
- => " Results may be capped by default limit of 50 returned results. Use --limit to extend the result set."
99
- case _
100
- => " "
101
- }
96
+ private def processResults (config : Config , results : List [SearchResult ], queryRuntime : Double ) = {
97
+ val capMessage = {
98
+ config.limit match {
99
+ case Some (limit) if (limit <= results.size)
100
+ => s " Results may be capped by result limit set to $limit. "
101
+ case None if (results.size >= 50 )
102
+ => " Results may be capped by default limit of 50 returned results. Use --limit to extend the result set."
103
+ case _
104
+ => " "
102
105
}
103
- success(config)(s " Found ${unmarshalled.size} item(s). $capMessage" )
104
- reportResult(config)(unmarshalled)
105
-
106
-
107
- information(config)(f " Query took $took%.2fs. " )
108
106
}
107
+ success(config)(s " Found ${results.size} item(s). $capMessage" )
108
+ reportResult(config)(results)
109
+
110
+ information(config)(f " Query took $queryRuntime%.2fs. " )
109
111
}
110
112
111
113
case class Query (query : String ,
0 commit comments