O'Reilly logo

Distributed Computing with Go by V.N. Nikhil Anurag

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

api/query.go

Source file contains code responsible for returning sorted results based on search terms.

package api import ( "encoding/json" "net/http" "sort" "github.com/last-ent/distributed-go/chapter7/goophr/librarian/common" ) type docResult struct { DocID string 'json:"doc_id"' Score int 'json:"doc_score"' Indices tIndices 'json:"token_indices"' } type result struct { Count int 'json:"count"' Data []docResult 'json:"data"' } // getResults returns unsorted search results & a map of documents containing tokens. func getResults(out chan tcMsg, count int) tCatalog { tc := tCatalog{} for i := 0; i < count; i++ { dc := <-out tc[dc.Token] = dc.DC } close(out) return tc } func getFScores(docIDScore map[string]int) (map[int][]string, []int) { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required