本站源代码
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.

89 line
1.6KB

  1. // Copyright 2018 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 issues
  5. import (
  6. "os"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestBleveIndexAndSearch(t *testing.T) {
  11. dir := "./bleve.index"
  12. indexer := NewBleveIndexer(dir)
  13. defer os.RemoveAll(dir)
  14. _, err := indexer.Init()
  15. assert.NoError(t, err)
  16. err = indexer.Index([]*IndexerData{
  17. {
  18. ID: 1,
  19. RepoID: 2,
  20. Title: "Issue search should support Chinese",
  21. Content: "As title",
  22. Comments: []string{
  23. "test1",
  24. "test2",
  25. },
  26. },
  27. {
  28. ID: 2,
  29. RepoID: 2,
  30. Title: "CJK support could be optional",
  31. Content: "Chinese Korean and Japanese should be supported but I would like it's not enabled by default",
  32. Comments: []string{
  33. "LGTM",
  34. "Good idea",
  35. },
  36. },
  37. })
  38. assert.NoError(t, err)
  39. var (
  40. keywords = []struct {
  41. Keyword string
  42. IDs []int64
  43. }{
  44. {
  45. Keyword: "search",
  46. IDs: []int64{1},
  47. },
  48. {
  49. Keyword: "test1",
  50. IDs: []int64{1},
  51. },
  52. {
  53. Keyword: "test2",
  54. IDs: []int64{1},
  55. },
  56. {
  57. Keyword: "support",
  58. IDs: []int64{1, 2},
  59. },
  60. {
  61. Keyword: "chinese",
  62. IDs: []int64{1, 2},
  63. },
  64. {
  65. Keyword: "help",
  66. IDs: []int64{},
  67. },
  68. }
  69. )
  70. for _, kw := range keywords {
  71. res, err := indexer.Search(kw.Keyword, 2, 10, 0)
  72. assert.NoError(t, err)
  73. var ids = make([]int64, 0, len(res.Hits))
  74. for _, hit := range res.Hits {
  75. ids = append(ids, hit.ID)
  76. }
  77. assert.EqualValues(t, kw.IDs, ids)
  78. }
  79. }
上海开阖软件有限公司 沪ICP备12045867号-1