本文整理匯總了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
}