diff options
Diffstat (limited to 'modules/indexer/issues')
-rw-r--r-- | modules/indexer/issues/bleve.go | 16 | ||||
-rw-r--r-- | modules/indexer/issues/bleve_test.go | 2 | ||||
-rw-r--r-- | modules/indexer/issues/db.go | 7 | ||||
-rw-r--r-- | modules/indexer/issues/indexer.go | 11 | ||||
-rw-r--r-- | modules/indexer/issues/indexer_test.go | 16 |
5 files changed, 29 insertions, 23 deletions
diff --git a/modules/indexer/issues/bleve.go b/modules/indexer/issues/bleve.go index 36279198b8..24443e54a3 100644 --- a/modules/indexer/issues/bleve.go +++ b/modules/indexer/issues/bleve.go @@ -218,9 +218,18 @@ func (b *BleveIndexer) Delete(ids ...int64) error { // Search searches for issues by given conditions. // Returns the matching issue IDs -func (b *BleveIndexer) Search(keyword string, repoID int64, limit, start int) (*SearchResult, error) { +func (b *BleveIndexer) Search(keyword string, repoIDs []int64, limit, start int) (*SearchResult, error) { + var repoQueriesP []*query.NumericRangeQuery + for _, repoID := range repoIDs { + repoQueriesP = append(repoQueriesP, numericEqualityQuery(repoID, "RepoID")) + } + repoQueries := make([]query.Query, len(repoQueriesP)) + for i, v := range repoQueriesP { + repoQueries[i] = query.Query(v) + } + indexerQuery := bleve.NewConjunctionQuery( - numericEqualityQuery(repoID, "RepoID"), + bleve.NewDisjunctionQuery(repoQueries...), bleve.NewDisjunctionQuery( newMatchPhraseQuery(keyword, "Title", issueIndexerAnalyzer), newMatchPhraseQuery(keyword, "Content", issueIndexerAnalyzer), @@ -242,8 +251,7 @@ func (b *BleveIndexer) Search(keyword string, repoID int64, limit, start int) (* return nil, err } ret.Hits = append(ret.Hits, Match{ - ID: id, - RepoID: repoID, + ID: id, }) } return &ret, nil diff --git a/modules/indexer/issues/bleve_test.go b/modules/indexer/issues/bleve_test.go index 8ec274566f..94d935d89d 100644 --- a/modules/indexer/issues/bleve_test.go +++ b/modules/indexer/issues/bleve_test.go @@ -76,7 +76,7 @@ func TestBleveIndexAndSearch(t *testing.T) { ) for _, kw := range keywords { - res, err := indexer.Search(kw.Keyword, 2, 10, 0) + res, err := indexer.Search(kw.Keyword, []int64{2}, 10, 0) assert.NoError(t, err) var ids = make([]int64, 0, len(res.Hits)) diff --git a/modules/indexer/issues/db.go b/modules/indexer/issues/db.go index 6e7f0c1a6e..7d4e389471 100644 --- a/modules/indexer/issues/db.go +++ b/modules/indexer/issues/db.go @@ -26,8 +26,8 @@ func (db *DBIndexer) Delete(ids ...int64) error { } // Search dummy function -func (db *DBIndexer) Search(kw string, repoID int64, limit, start int) (*SearchResult, error) { - total, ids, err := models.SearchIssueIDsByKeyword(kw, repoID, limit, start) +func (db *DBIndexer) Search(kw string, repoIDs []int64, limit, start int) (*SearchResult, error) { + total, ids, err := models.SearchIssueIDsByKeyword(kw, repoIDs, limit, start) if err != nil { return nil, err } @@ -37,8 +37,7 @@ func (db *DBIndexer) Search(kw string, repoID int64, limit, start int) (*SearchR } for _, id := range ids { result.Hits = append(result.Hits, Match{ - ID: id, - RepoID: repoID, + ID: id, }) } return &result, nil diff --git a/modules/indexer/issues/indexer.go b/modules/indexer/issues/indexer.go index 4f410daf4c..76da46d759 100644 --- a/modules/indexer/issues/indexer.go +++ b/modules/indexer/issues/indexer.go @@ -28,9 +28,8 @@ type IndexerData struct { // Match represents on search result type Match struct { - ID int64 `json:"id"` - RepoID int64 `json:"repo_id"` - Score float64 `json:"score"` + ID int64 `json:"id"` + Score float64 `json:"score"` } // SearchResult represents search results @@ -44,7 +43,7 @@ type Indexer interface { Init() (bool, error) Index(issue []*IndexerData) error Delete(ids ...int64) error - Search(kw string, repoID int64, limit, start int) (*SearchResult, error) + Search(kw string, repoIDs []int64, limit, start int) (*SearchResult, error) } type indexerHolder struct { @@ -262,9 +261,9 @@ func DeleteRepoIssueIndexer(repo *models.Repository) { } // SearchIssuesByKeyword search issue ids by keywords and repo id -func SearchIssuesByKeyword(repoID int64, keyword string) ([]int64, error) { +func SearchIssuesByKeyword(repoIDs []int64, keyword string) ([]int64, error) { var issueIDs []int64 - res, err := holder.get().Search(keyword, repoID, 1000, 0) + res, err := holder.get().Search(keyword, repoIDs, 1000, 0) if err != nil { return nil, err } diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go index 212c2edfbe..a45fede9ac 100644 --- a/modules/indexer/issues/indexer_test.go +++ b/modules/indexer/issues/indexer_test.go @@ -30,19 +30,19 @@ func TestBleveSearchIssues(t *testing.T) { time.Sleep(5 * time.Second) - ids, err := SearchIssuesByKeyword(1, "issue2") + ids, err := SearchIssuesByKeyword([]int64{1}, "issue2") assert.NoError(t, err) assert.EqualValues(t, []int64{2}, ids) - ids, err = SearchIssuesByKeyword(1, "first") + ids, err = SearchIssuesByKeyword([]int64{1}, "first") assert.NoError(t, err) assert.EqualValues(t, []int64{1}, ids) - ids, err = SearchIssuesByKeyword(1, "for") + ids, err = SearchIssuesByKeyword([]int64{1}, "for") assert.NoError(t, err) assert.EqualValues(t, []int64{1, 2, 3, 5}, ids) - ids, err = SearchIssuesByKeyword(1, "good") + ids, err = SearchIssuesByKeyword([]int64{1}, "good") assert.NoError(t, err) assert.EqualValues(t, []int64{1}, ids) } @@ -53,19 +53,19 @@ func TestDBSearchIssues(t *testing.T) { setting.Indexer.IssueType = "db" InitIssueIndexer(true) - ids, err := SearchIssuesByKeyword(1, "issue2") + ids, err := SearchIssuesByKeyword([]int64{1}, "issue2") assert.NoError(t, err) assert.EqualValues(t, []int64{2}, ids) - ids, err = SearchIssuesByKeyword(1, "first") + ids, err = SearchIssuesByKeyword([]int64{1}, "first") assert.NoError(t, err) assert.EqualValues(t, []int64{1}, ids) - ids, err = SearchIssuesByKeyword(1, "for") + ids, err = SearchIssuesByKeyword([]int64{1}, "for") assert.NoError(t, err) assert.EqualValues(t, []int64{1, 2, 3, 5}, ids) - ids, err = SearchIssuesByKeyword(1, "good") + ids, err = SearchIssuesByKeyword([]int64{1}, "good") assert.NoError(t, err) assert.EqualValues(t, []int64{1}, ids) } |