The clients of the in-memory indexer submit search queries by invoking the Search method. The implementation of this method is as follows:
func (i *InMemoryBleveIndexer) Search(q index.Query) (index.Iterator, error) { var bq query.Query switch q.Type { case index.QueryTypePhrase: bq = bleve.NewMatchPhraseQuery(q.Expression) default: bq = bleve.NewMatchQuery(q.Expression) } searchReq := bleve.NewSearchRequest(bq) searchReq.SortBy([]string{"-PageRank", "-_score"}) searchReq.Size = batchSize searchReq.From = q.Offset rs, err := i.idx.Search(searchReq) if err != nil { return nil, xerrors.Errorf("search: %w", err) } return &bleveIterator{idx: i, searchReq: searchReq, rs: rs, cumIdx: q.Offset}, nil }
The first thing that our implementation needs to do is check what type of query the caller asked us to perform and then invoke the appropriate bleve helper to construct a query from the caller-provided expression.
Next, the generated query is transformed into a new search request where we also ask bleve to order the results by PageRank and relevance in descending order. Bleve search results are always paginated. Consequently, in addition to any sorting preferences, we must also specify the number of results per page that we want bleve to return (the batch size). The search request object also allows us to control the offset in the result list by specifying a value for its From field.
The next step is to submit the search request to bleve and check for the presence of errors. If everything goes according to plan and no error is returned, the implementation creates a new iterator instance that the caller can use to consume the matched documents.