You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

indexer.go 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2016 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package indexer
  5. import (
  6. "fmt"
  7. "strconv"
  8. "github.com/blevesearch/bleve"
  9. "github.com/blevesearch/bleve/search/query"
  10. )
  11. // indexerID a bleve-compatible unique identifier for an integer id
  12. func indexerID(id int64) string {
  13. return strconv.FormatInt(id, 36)
  14. }
  15. // idOfIndexerID the integer id associated with an indexer id
  16. func idOfIndexerID(indexerID string) (int64, error) {
  17. id, err := strconv.ParseInt(indexerID, 36, 64)
  18. if err != nil {
  19. return 0, fmt.Errorf("Unexpected indexer ID %s: %v", indexerID, err)
  20. }
  21. return id, nil
  22. }
  23. // numericEqualityQuery a numeric equality query for the given value and field
  24. func numericEqualityQuery(value int64, field string) *query.NumericRangeQuery {
  25. f := float64(value)
  26. tru := true
  27. q := bleve.NewNumericRangeInclusiveQuery(&f, &f, &tru, &tru)
  28. q.SetField(field)
  29. return q
  30. }
  31. func newMatchPhraseQuery(matchPhrase, field, analyzer string) *query.MatchPhraseQuery {
  32. q := bleve.NewMatchPhraseQuery(matchPhrase)
  33. q.FieldVal = field
  34. q.Analyzer = analyzer
  35. return q
  36. }