mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-17 02:47:51 +01:00
Fix returned status in /search/result
This commit is contained in:
@@ -23,6 +23,7 @@ func (api *WebapiInstance) dispatchSearch(input SearchRequest) (job *SearchJob)
|
||||
job = CreateSearchJob(Timeout, input.MaxResults, Filter)
|
||||
|
||||
// todo: create actual search clients!
|
||||
job.Status = SearchStatusLive
|
||||
|
||||
go job.localSearch(api, input.Term)
|
||||
|
||||
@@ -33,6 +34,7 @@ func (api *WebapiInstance) dispatchSearch(input SearchRequest) (job *SearchJob)
|
||||
|
||||
func (job *SearchJob) localSearch(api *WebapiInstance, term string) {
|
||||
if api.backend.SearchIndex == nil || api.backend.GlobalBlockchainCache == nil {
|
||||
job.Status = SearchStatusNoIndex
|
||||
return
|
||||
}
|
||||
|
||||
@@ -75,6 +77,8 @@ resultLoop:
|
||||
job.statsAdd(&newFile)
|
||||
}
|
||||
|
||||
job.Status = SearchStatusTerminated
|
||||
|
||||
job.ResultSync.Unlock()
|
||||
job.Terminate()
|
||||
}
|
||||
|
||||
@@ -48,6 +48,9 @@ type SearchJob struct {
|
||||
|
||||
// -- result data --
|
||||
|
||||
// Status indicates the overall search status. This will be removed later when relying on search clients.
|
||||
Status int
|
||||
|
||||
// runtime data
|
||||
//clients []*SearchClient // all search clients
|
||||
clientsMutex sync.Mutex // mutex for manipulating client list
|
||||
@@ -67,10 +70,18 @@ type SearchJob struct {
|
||||
currentOffset int // for always getting the next results
|
||||
}
|
||||
|
||||
const (
|
||||
SearchStatusNotStarted = iota // Search was not yet started
|
||||
SearchStatusLive // Search running
|
||||
SearchStatusTerminated // Search is terminated. No more results are expected.
|
||||
SearchStatusNoIndex // Search is terminated. No search index to use.
|
||||
)
|
||||
|
||||
// CreateSearchJob creates a new search job and adds it to the lookup list.
|
||||
// Timeout and MaxResults must be set and must not be 0.
|
||||
func CreateSearchJob(Timeout time.Duration, MaxResults int, Filter SearchFilter) (job *SearchJob) {
|
||||
job = &SearchJob{}
|
||||
job.Status = SearchStatusNotStarted
|
||||
job.id = uuid.New()
|
||||
job.timeout = Timeout
|
||||
job.maxResult = MaxResults
|
||||
|
||||
@@ -169,12 +169,23 @@ func apiSearchResult(w http.ResponseWriter, r *http.Request) {
|
||||
result.Files = append(result.Files, *resultFiles[n])
|
||||
}
|
||||
|
||||
if len(result.Files) == 0 {
|
||||
// set the status
|
||||
if len(result.Files) > 0 {
|
||||
result.Status = 0 // 0 = Success with results
|
||||
} else {
|
||||
switch job.Status {
|
||||
case SearchStatusLive:
|
||||
result.Status = 3 // No results yet available keep trying
|
||||
|
||||
case SearchStatusTerminated:
|
||||
result.Status = 1 // No more results to expect
|
||||
|
||||
default: // SearchStatusNoIndex, SearchStatusNotStarted
|
||||
result.Status = 1 // No more results to expect
|
||||
}
|
||||
}
|
||||
|
||||
//if !job.IsSearchResults() { // if no fresh results to be expected
|
||||
result.Status = 1 // No more results to expect
|
||||
|
||||
// embedded statistics?
|
||||
if returnStats, _ := strconv.ParseBool(r.Form.Get("stats")); returnStats {
|
||||
|
||||
Reference in New Issue
Block a user