@@ -21,8 +21,8 @@ import java.util.concurrent.TimeUnit
2121import com .softwaremill .sttp ._
2222import com .softwaremill .sttp .sprayJson ._
2323import de .upb .cs .swt .delphi .cli .Config
24- import de .upb .cs .swt .delphi .cli .artifacts .SearchResult
25- import de .upb .cs .swt .delphi .cli .artifacts .SearchResultJson ._
24+ import de .upb .cs .swt .delphi .cli .artifacts .{ SearchResult , SearchResults }
25+ import de .upb .cs .swt .delphi .cli .artifacts .SearchResultsJson ._
2626import spray .json ._
2727
2828import scala .concurrent .duration ._
@@ -43,10 +43,8 @@ object SearchCommand extends Command with DefaultJsonProtocol{
4343
4444 information.apply(s " Searching for artifacts matching ${'"' }$query${'"' }. " )
4545
46-
47- val queryParams = Map (" pretty" -> " " )
4846 val queryPayload : Query = Query (query,config.limit)
49- val searchUri = uri " ${config.server}/search? $queryParams "
47+ val searchUri = uri " ${config.server}/search "
5048
5149 val request = sttp.body(queryPayload.toJson).post(searchUri)
5250
@@ -64,7 +62,7 @@ object SearchCommand extends Command with DefaultJsonProtocol{
6462
6563 if (res.code == timeoutCode) {
6664
67- error.apply(s " The query timed out after ${took.toSeconds} seconds. " +
65+ error.apply(s " The query timed out after ${took.toSeconds}%.0f seconds. " +
6866 " To set a longer timeout, use the --timeout option." )
6967 }
7068 val resStr = res.body match {
@@ -83,28 +81,27 @@ object SearchCommand extends Command with DefaultJsonProtocol{
8381 reportResult.apply(res)
8482 }
8583 if (! (config.raw || res.equals(" " )) || ! config.csv.equals(" " )) {
86- val jsonArr = res.parseJson.asInstanceOf [JsArray ].elements
87- val retrieveResults = jsonArr.map(r => r.convertTo[SearchResult ]).toList
88- onProperSearchResults(retrieveResults)
89- }
90-
91- def onProperSearchResults (sr : List [SearchResult ]) = {
92-
84+ val retrieveResults = res.parseJson.convertTo[SearchResults ]
85+ val sr = retrieveResults.hits.toList
9386 val capMessage = {
94- config.limit match {
95- case Some (limit) if (limit <= sr.size)
96- => s " Results may be capped by result limit set to $limit. "
97- case None if (sr.size >= 50 )
98- => " Results may be capped by default limit of 50 returned results. Use --limit to extend the result set."
99- case _
100- => " "
87+ if (sr.size < retrieveResults.totalHits ) {
88+ config.limit match {
89+ case Some (limit) if (limit <= sr.size)
90+ => s " Results are capped by results limit set to $limit. "
91+ case None if (sr.size >= 50 )
92+ => " Results are capped by default limit of 50 returned results. Use --limit to extend the result set."
93+ case _
94+ => " "
95+ }
96+ } else {
97+ " "
10198 }
10299 }
103100
104- success.apply(s " Found ${sr.size } item(s). $capMessage" )
101+ success.apply(s " Found ${retrieveResults.totalHits } item(s). $capMessage" )
105102 reportResult.apply(sr)
106103
107- information.apply(f " Query took ${queryRuntime.toUnit(TimeUnit .SECONDS )}%.2fs . " )
104+ information.apply(f " Query roundtrip took ${queryRuntime.toUnit(TimeUnit .MILLISECONDS )}%.0fms . " )
108105
109106 if (! config.csv.equals(" " )) {
110107 exportResult.apply(sr)
0 commit comments