January 2020
Intermediate to advanced
640 pages
16h 56m
English
Searching and paginating results is more or less a straightforward task for the frontend service. All our service needs to do is parse the search terms, offset from the request's query string, and invoke the Query method of the text indexer store that was passed as a configuration option when the service was instantiated.
Then, the service consumes the result iterator until it has either processed enough results to populate the results page or the iterator reaches the end of the result set. Consider the following code:
for resCount := 0; resultIt.Next() && resCount < svc.cfg.ResultsPerPage; resCount++ { doc := resultIt.Document() matchedDocs = append(matchedDocs, matchedDoc{ doc: doc, summary: highlighter.Highlight( ...