Skip to Content
Hands-On Software Engineering with Golang
book

Hands-On Software Engineering with Golang

by Achilleas Anagnostopoulos
January 2020
Intermediate to advanced
640 pages
16h 56m
English
Packt Publishing
Content preview from Hands-On Software Engineering with Golang

Searching the index

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Software Architecture with Golang

Hands-On Software Architecture with Golang

Jyotiswarup Raiturkar

Publisher Resources

ISBN: 9781838554491Supplemental Content