当前位置: 首页>>代码示例>>Golang>>正文


Golang bleve.NewSearchRequest函数代码示例

本文整理汇总了Golang中github.com/blevesearch/bleve.NewSearchRequest函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSearchRequest函数的具体用法?Golang NewSearchRequest怎么用?Golang NewSearchRequest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewSearchRequest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
开发者ID:pmezard,项目名称:apec,代码行数:30,代码来源:web.go

示例2: Search

func (self *Wiki) Search(queryString string) ([]*SearchResult, error) {
	query := bleve.NewMatchQuery(queryString)
	search := bleve.NewSearchRequest(query)
	search.Highlight = bleve.NewHighlight()
	searchResult, err := self.Index.Search(search)
	if err != nil {
		return nil, err
	}
	results := []*SearchResult{}
	for _, result := range searchResult.Hits {
		section, article := self.Find(result.ID)
		if article == nil && section == nil {
			return nil, fmt.Errorf("%v section or article not found", result.ID)
		}
		text := ""
		for _, values := range result.Fragments {
			for _, value := range values {
				text += value
			}
		}
		name := ""
		if section != nil {
			name = section.Name
		}
		if article != nil {
			name = article.Name
		}
		results = append(results, &SearchResult{Path: result.ID, Name: name, Text: text})
	}
	return results, nil
}
开发者ID:romanoff,项目名称:gowiki,代码行数:31,代码来源:section.go

示例3: search

func search(cfg *Config) error {
	store, err := OpenStore(cfg.Store())
	if err != nil {
		return err
	}
	index, err := bleve.Open(cfg.Index())
	if err != nil {
		return err
	}
	defer index.Close()
	q, err := makeSearchQuery(*searchQuery, nil)
	if err != nil {
		return err
	}
	rq := bleve.NewSearchRequest(q)
	rq.Size = 100
	ids := []string{}
	for {
		res, err := index.Search(rq)
		if err != nil {
			return err
		}
		for _, doc := range res.Hits {
			ids = append(ids, doc.ID)
		}
		if len(res.Hits) < rq.Size {
			break
		}
		rq.From += rq.Size
	}
	return printOffers(store, ids)
}
开发者ID:pmezard,项目名称:apec,代码行数:32,代码来源:search.go

示例4: Search

// Search method lookup for records using a query
func (i *bleveIndexer) Search(q string) (records []indexer.Record) {
	query := bleve.NewQueryStringQuery(q)
	request := bleve.NewSearchRequest(query)
	request.Highlight = bleve.NewHighlight()
	result, err := i.bleve.Search(request)
	if err != nil { // an empty query would cause this
		return
	}

	for _, match := range result.Hits {
		rec := i.Record(match.ID)
		loaded := rec.Load()

		if !loaded {
			continue
		}

		if len(match.Fragments["Body"]) > 0 {
			rec.SetBody([]byte(match.Fragments["Body"][0]))
		}

		records = append(records, rec)
	}

	return
}
开发者ID:pedronasser,项目名称:caddy-search,代码行数:27,代码来源:indexer.go

示例5: main

func main() {
	// open a new index
	mapping := bleve.NewIndexMapping()
	index, err := bleve.New("example.bleve", mapping)
	if err != nil {
		fmt.Println(err)
		return
	}

	data := struct {
		Name string
	}{
		Name: "text",
	}

	// index some data
	index.Index("id", data)

	// search for some text
	query := bleve.NewMatchQuery("text")
	search := bleve.NewSearchRequest(query)
	searchResults, err := index.Search(search)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(searchResults)
}
开发者ID:joyrexus,项目名称:go-sandbox,代码行数:28,代码来源:hello.go

示例6: Search

func (docstore *DocStoreExt) Search(collection, queryString string) ([]byte, error) {
	js := []byte{}
	query := bleve.NewQueryStringQuery(queryString)
	searchRequest := bleve.NewSearchRequest(query)
	searchResult, err := docstore.index.Search(searchRequest)
	if err != nil {
		return nil, err
	}
	for index, sr := range searchResult.Hits {
		jsPart := []byte{}
		_, err := docstore.fetchDoc(collection, sr.ID, &jsPart)
		if err != nil {
			return nil, err
		}
		js = append(js, addID(jsPart, sr.ID)...)
		if index != len(searchResult.Hits)-1 {
			js = append(js, []byte(",")...)
		}
	}
	if len(searchResult.Hits) > 0 {
		js = js[0 : len(js)-1]
	}
	js = append(js, []byte("]")...)
	// "_meta": searchResult,
	// "data":  docs,
	// TODO(tsileo) returns meta along with argument
	return js, nil
}
开发者ID:marsmensch,项目名称:blobstash,代码行数:28,代码来源:docstore.go

示例7: main

func main() {
	// Open an index if it already exists.
	index, err := bleve.Open("example.bleve")
	if err != nil {
		mapping := bleve.NewIndexMapping()
		index, err = bleve.New("example.bleve", mapping)
		if err != nil {
			fmt.Println(err)
			return
		}
	}

	data := struct {
		Name string
	}{
		Name: "text",
	}

	// Index some data.
	index.Index("id", data)

	// Search for some text
	query := bleve.NewMatchQuery("text")
	search := bleve.NewSearchRequest(query)
	searchResults, err := index.Search(search)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(searchResults)
}
开发者ID:DexterB,项目名称:Go,代码行数:32,代码来源:easysearch.go

示例8: Search

// Search is an http.HandlerFunc that accepts a Parse Cloud Code Webhook request.
//
// The expected query parameter is 'q'
func (i *Indexer) Search(w http.ResponseWriter, r *http.Request) {
	req, err := webhookRequest(r, i.webhookKey)
	if err != nil {
		writeErr(w, err)
		return
	}
	rawq := req.Params["q"]
	if rawq == nil {
		writeErr(w, fmt.Errorf("no term provided"))
		return
	}
	q, ok := rawq.(string)
	if q == "" || !ok {
		writeErr(w, fmt.Errorf("no term provided"))
		return
	}
	query := bleve.NewQueryStringQuery(q)
	search := bleve.NewSearchRequest(query)
	searchResults, err := i.index.Search(search)
	if err != nil {
		writeErr(w, err)
		return
	}
	spew.Dump(searchResults)
	ids := []string{}
	for _, h := range searchResults.Hits {
		ids = append(ids, h.ID)
	}
	err = json.NewEncoder(w).Encode(Response{
		Success: ids,
	})
	if err != nil {
		log.Println("error encoding response:", err)
	}
}
开发者ID:tmc,项目名称:parsesearch,代码行数:38,代码来源:indexer.go

示例9: TestFindByAnything

func TestFindByAnything(t *testing.T) {
	db, eventList := dbCreate()
	idx := idxCreate()
	indexEvents(idx, eventList)

	// We are looking to an Event with some string which match with dotGo
	query := bleve.NewMatchQuery("dotGo")
	searchRequest := bleve.NewSearchRequest(query)
	searchResult, err := idx.Search(searchRequest)
	if err != nil {
		t.Error("Something wrong happen with the search", err, ballotX)
	} else {
		t.Log("Should search the query", checkMark)
	}

	if searchResult.Total != 1 {
		t.Error("Only 1 result are expected, got ", searchResult.Total, ballotX)
	} else {
		t.Log("Should return only one result", checkMark)
	}

	event := &Event{}
	db.First(&event, &searchResult.Hits[0].ID)
	if event.Name != "dotGo 2015" {
		t.Error("Expected \"dotGo 2015\", Receive: ", event.Name)
	} else {
		t.Log("Should return an event with the name equal a", event.Name, checkMark)
	}

	idxDestroy()
	dbDestroy()
}
开发者ID:nassor,项目名称:studies-blevesearch,代码行数:32,代码来源:event_test.go

示例10: jobTags

func jobTags(w http.ResponseWriter, r *http.Request) {

	query := bleve.NewMatchAllQuery()

	searchRequest := bleve.NewSearchRequest(query)
	searchRequest.Fields = []string{"tags"}

	tagsFacet := bleve.NewFacetRequest("tags", 99999)
	searchRequest.AddFacet("tags", tagsFacet)

	jobsSearchResults, err := doRequest("jobs", searchRequest)
	if err != nil {
		respond.With(w, r, http.StatusInternalServerError, err)
		return
	}

	tags := []string{}
	for _, t := range jobsSearchResults.Facets["tags"].Terms {
		tags = append(tags, fmt.Sprintf("%s", t.Term))
	}

	respond.With(w, r, http.StatusOK, struct {
		Total int      `json:"total"`
		Tags  []string `json:"tags"`
	}{
		Total: len(tags),
		Tags:  tags,
	})
}
开发者ID:fairlance,项目名称:backend,代码行数:29,代码来源:main.go

示例11: 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
}
开发者ID:pmezard,项目名称:apec,代码行数:59,代码来源:density.go

示例12: Search

func (be *BleveEngine) Search(query string) (interface{}, error) {
	index, _ := bleve.Open(INDEX)
	bleveQuery := bleve.NewQueryStringQuery(query)
	searchRequest := bleve.NewSearchRequest(bleveQuery)
	searchResults, err := index.Search(searchRequest)
	if err != nil {
		return nil, err
	}

	return searchResults, nil
}
开发者ID:dorsha,项目名称:lennon,代码行数:11,代码来源:BleveEngine.go

示例13: Search

//See https://godoc.org/github.com/blevesearch/bleve#SearchResult
func Search(keyword string) (*bleve.SearchResult, error) {
	fmt.Println(keyword)

	query := bleve.NewMatchQuery(keyword)
	request := bleve.NewSearchRequest(query)
	request.Size = 20
	//request.Fields = []string{"Name", "Text", "Size", "IsDir", "ModTime"}

	result, err := LimeIndex.Search(request)
	if err != nil {
		return nil, err
	}
	return result, nil
}
开发者ID:misakik,项目名称:f3,代码行数:15,代码来源:search.go

示例14: main

// START OMIT
func main() {
	index, err := bleve.Open("people.bleve") // HLOPEN
	if err != nil {
		log.Fatal(err)
	}

	query := bleve.NewTermQuery("marty")     // HLQUERY
	request := bleve.NewSearchRequest(query) // HLREQ
	result, err := index.Search(request)     // HLSEARCH
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(result)
}
开发者ID:blevesearch,项目名称:gophercon15,代码行数:15,代码来源:search.go

示例15: TestBeerSearchBug87

// this test reproduces bug #87
// https://github.com/blevesearch/bleve/issues/87
// because of which, it will deadlock
func TestBeerSearchBug87(t *testing.T) {
	defer os.RemoveAll("beer-search-test.bleve")

	mapping, err := buildIndexMapping()
	if err != nil {
		t.Fatal(err)
	}
	index, err := bleve.New("beer-search-test.bleve", mapping)
	if err != nil {
		t.Fatal(err)
	}
	defer index.Close()

	// start indexing documents in the background
	go func() {
		// open the directory
		dirEntries, err := ioutil.ReadDir("data/")
		if err != nil {
			t.Fatal(err)
		}

		for _, dirEntry := range dirEntries {
			filename := dirEntry.Name()
			jsonBytes, err := ioutil.ReadFile("data/" + filename)
			if err != nil {
				t.Fatal(err)
			}
			ext := filepath.Ext(filename)
			docId := filename[:(len(filename) - len(ext))]
			index.Index(docId, jsonBytes)
		}
	}()

	// give indexing a head start
	time.Sleep(1 * time.Second)

	// start querying
	for i := 0; i < 1000; i++ {
		time.Sleep(1 * time.Millisecond)
		termQuery := bleve.NewTermQuery("shock").SetField("name")
		termSearchRequest := bleve.NewSearchRequest(termQuery)
		// termSearchRequest.AddFacet("styles", bleve.NewFacetRequest("style", 3))
		termSearchRequest.Fields = []string{"abv"}
		_, err := index.Search(termSearchRequest)
		if err != nil {
			t.Error(err)
		}
	}
}
开发者ID:Xackery,项目名称:beer-search,代码行数:52,代码来源:main_test.go


注:本文中的github.com/blevesearch/bleve.NewSearchRequest函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。