本文整理汇总了Golang中github.com/blevesearch/bleve.Index.Search方法的典型用法代码示例。如果您正苦于以下问题:Golang Index.Search方法的具体用法?Golang Index.Search怎么用?Golang Index.Search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/blevesearch/bleve.Index
的用法示例。
在下文中一共展示了Index.Search方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: findOffersFromText
func findOffersFromText(index bleve.Index, query string, ids []string) (
[]datedOffer, error) {
if query == "" {
return nil, nil
}
datedOffers := []datedOffer{}
q, err := makeSearchQuery(query, ids)
if err != nil {
return nil, err
}
rq := bleve.NewSearchRequest(q)
rq.Size = 20000
rq.Fields = []string{"date"}
res, err := index.Search(rq)
if err != nil {
return nil, err
}
for _, doc := range res.Hits {
date, ok := doc.Fields["date"].(string)
if !ok {
return nil, fmt.Errorf("could not retrieve date for %s", doc.ID)
}
datedOffers = append(datedOffers, datedOffer{
Date: date,
Id: doc.ID,
})
}
return datedOffers, nil
}
示例2: listPoints
// listPoints returns the location of offers satisfying specified full-text
// query. If query is empty, it returns all locations. If not nil, spatial is
// exploited as a cache to fetch indexed offers and their locations, which
// avoid store lookups.
func listPoints(store *Store, index bleve.Index, spatial *SpatialIndex,
query string) ([]Point, error) {
var ids []string
if query == "" {
if spatial != nil {
ids = spatial.List()
} else {
list, err := store.List()
if err != nil {
return nil, err
}
ids = list
}
} else {
q, err := makeSearchQuery(query, nil)
if err != nil {
return nil, err
}
rq := bleve.NewSearchRequest(q)
rq.Size = 20000
res, err := index.Search(rq)
if err != nil {
return nil, err
}
for _, doc := range res.Hits {
ids = append(ids, doc.ID)
}
}
points := make([]Point, 0, len(ids))
for _, id := range ids {
var p *Point
if spatial != nil {
offer := spatial.Get(id)
if offer != nil {
p = &offer.Point
}
}
if p == nil {
loc, _, err := store.GetLocation(id)
if err != nil {
return nil, err
}
if loc == nil {
continue
}
p = &Point{
Lat: loc.Lat,
Lon: loc.Lon,
}
}
points = append(points, *p)
}
return points, nil
}
示例3: queryWorker
func queryWorker(index bleve.Index, sr *bleve.SearchRequest, repeat int) {
termQueryCount := 0
for termQueryCount < repeat {
termQueryStart := time.Now()
_, err := index.Search(sr)
if err != nil {
log.Fatal(err)
}
atomic.AddUint64(&totalRequests, 1)
atomic.AddUint64(&totalTimeTaken, uint64(time.Since(termQueryStart)))
termQueryCount++
}
}
示例4: Query
func (indexes *BleveIndexes) Query(namespace string, query interface{}, offset int64, size int64) (int64, []string, error) {
var total int64 = 0
var uris []string
indexes.RLock()
defer indexes.RUnlock()
node := indexes.nodes.Node(namespace)
if node == nil {
return total, uris, fmt.Errorf("none node for namespace: %s", namespace)
}
var idx bleve.Index
if node.GetBind() == nil {
index, err := indexes.index(namespace, false)
if err != nil {
return total, uris, err
}
if index == nil {
return total, uris, nil
}
node.SetBind(index)
idx = index
} else {
idx = node.GetBind().(bleve.Index)
}
q, ok := query.(bleve.Query)
if !ok {
return total, uris, fmt.Errorf("query type convert failed")
}
request := bleve.NewSearchRequestOptions(q, IndexSize, IndexOffset, false)
response, err := idx.Search(request)
if err != nil {
return total, uris, err
}
total = int64(response.Total)
for _, doc := range response.Hits {
uris = append(uris, doc.ID)
}
return total, uris, nil
}
示例5: query
func query(term, highlight string, index bleve.Index, u content.User, feedIds []data.FeedId, paging ...int) (ua []content.UserArticle, err error) {
var query bleve.Query
query = bleve.NewQueryStringQuery(term)
if len(feedIds) > 0 {
queries := make([]bleve.Query, len(feedIds))
conjunct := make([]bleve.Query, 2)
for i, id := range feedIds {
q := bleve.NewTermQuery(strconv.FormatInt(int64(id), 10))
q.SetField("FeedId")
queries[i] = q
}
disjunct := bleve.NewDisjunctionQuery(queries)
conjunct[0] = query
conjunct[1] = disjunct
query = bleve.NewConjunctionQuery(conjunct)
}
searchRequest := bleve.NewSearchRequest(query)
if highlight != "" {
searchRequest.Highlight = bleve.NewHighlightWithStyle(highlight)
}
limit, offset := pagingLimit(paging)
searchRequest.Size = limit
searchRequest.From = offset
searchResult, err := index.Search(searchRequest)
if err != nil {
return
}
if len(searchResult.Hits) == 0 {
return
}
articleIds := []data.ArticleId{}
hitMap := map[data.ArticleId]*search.DocumentMatch{}
for _, hit := range searchResult.Hits {
if articleId, err := strconv.ParseInt(hit.ID, 10, 64); err == nil {
id := data.ArticleId(articleId)
articleIds = append(articleIds, id)
hitMap[id] = hit
}
}
ua = u.ArticlesById(articleIds)
if u.HasErr() {
return ua, u.Err()
}
for i := range ua {
data := ua[i].Data()
hit := hitMap[data.Id]
if len(hit.Fragments) > 0 {
data.Hit.Fragments = hit.Fragments
ua[i].Data(data)
}
}
return
}