Exemplo n.º 1
0
func FetchByRelevanceAndDistance(s *solr.Solr, keywords string, lat float64, long float64, labels []string, startIndex int, limit int, maxDistance int) (result *solr.Result, err error) {

	var filterQuery string
	if len(labels) > 0 {
		filterQuery = "labels: (" + strings.Join(labels, " AND ") + ")"
	}
	query := solr.NewQuery(solr.AddFuzzyLogic(keywords), startIndex, limit)
	query.DefType(`edismax`)
	query.FilterQuery(filterQuery)
	query.QueryFields(`keywords^0.2 skills^0.7`)
	query.FilterQuery(`accounttype:FREE`)
	query.SpacialParam(lat, long, `location`, maxDistance)
	query.Sort(`score desc`)
	query.BoostFunction(solr.Recip(`geodist()`, 1, 1, 1, 4))
	query.AddHighlighter(`skills`, 2)

	result, err = s.Search(query)
	for _, val := range result.Highlights {
		fmt.Println(val.Id)
		if terms, ok := val.HighlightTerms[`skills`].([]interface{}); ok {
			for _, v := range terms {
				fmt.Println(v)
			}
		}

	}
	return

}
Exemplo n.º 2
0
func FetchSuggestions(s *solr.Solr, keyword string) {

	query := solr.NewSuggestQuery(keyword)
	res, _ := s.Suggest(query)

	fmt.Println(res.Suggestions)

}
Exemplo n.º 3
0
func FetchSampleRecordsByRelevance(s *solr.Solr, keywords string, startIndex int, limit int) (result *solr.Result, err error) {

	query := solr.NewQuery(solr.AddFuzzyLogic(keywords), startIndex, limit)
	query.DefType(`edismax`)
	query.QueryFields(`keywords^0.2 skills^0.7`)
	query.FilterQuery(`accounttype:EXAMPLE`)
	query.Sort(`score desc`)
	query.SpellcheckQuery(keywords)
	result, err = s.Search(query)

	return

}
Exemplo n.º 4
0
func FetchByDistance(s *solr.Solr, lat float64, long float64, labels []string, startIndex int, limit int, maxDistance int) (result *solr.Result, err error) {

	var filterQuery string
	if len(labels) > 0 {
		filterQuery = "labels: (" + strings.Join(labels, " AND ") + ")"
	}

	query := solr.NewQuery(`*:*`, startIndex, limit)
	query.FilterQuery(filterQuery)
	query.Geofilt(lat, long, `location`, maxDistance)
	query.FilterQuery(`accounttype:EXAMPLE`)
	query.Sort(`geodist() asc`)
	result, err = s.Search(query)

	return

}
Exemplo n.º 5
0
func addDocuments(s *solr.Solr) {
	doc1 := map[string]interface{}{`id`: `doc3`, `keywords`: `baby sitter`, `location`: `43.697225, -79.404949`, `labels`: []string{`SIDEJOB`}, `skills`: []string{`nanny`}, `accounttype`: `EXAMPLE`}
	err := s.AddDocuments(doc1)
	fmt.Println(err)

}