mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 14:31:02 +00:00 
			
		
		
		
	An attempt at solving #7956. This (and rebuilding the index) seems enough to ensure the issue *appears* among the results. However, I couldn't figure out from [bleve docs](https://github.com/blevesearch/bleve/blob/master/docs/scoring.md) how to affect the scoring based on specific fields, or whether that is possible at all. Disclaimer: I've never written Go before, sorry 😅 take it as a quick PoC more than anything. ### Tests - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. <!--start release-notes-assistant--> ## Release notes <!--URL:https://codeberg.org/forgejo/forgejo--> - Features - [PR](https://codeberg.org/forgejo/forgejo/pulls/7968): <!--number 7968 --><!--line 0 --><!--description QWRkIGlzc3VlIG51bWJlciB0byB0aGUgc2VhcmNoIGluZGV4LCByYW5rIG51bWJlciBhbmQgdGl0bGUgbWF0Y2hlcyBoaWdoZXIgKCM3OTU2KQ==-->Add issue number to the search index, rank number and title matches higher (#7956)<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7968 Reviewed-by: Shiny Nematoda <snematoda@noreply.codeberg.org> Co-authored-by: Danko Aleksejevs <danko@very.lv> Co-committed-by: Danko Aleksejevs <danko@very.lv>
This commit is contained in:
		
					parent
					
						
							
								2529923dea
							
						
					
				
			
			
				commit
				
					
						905a5748a8
					
				
			
		
					 9 changed files with 100 additions and 14 deletions
				
			
		|  | @ -23,7 +23,7 @@ import ( | |||
| const ( | ||||
| 	issueIndexerAnalyzer      = "issueIndexer" | ||||
| 	issueIndexerDocType       = "issueIndexerDocType" | ||||
| 	issueIndexerLatestVersion = 4 | ||||
| 	issueIndexerLatestVersion = 5 | ||||
| ) | ||||
| 
 | ||||
| const unicodeNormalizeName = "unicodeNormalize" | ||||
|  | @ -69,6 +69,7 @@ func generateIssueIndexMapping() (mapping.IndexMapping, error) { | |||
| 
 | ||||
| 	docMapping.AddFieldMappingsAt("is_public", boolFieldMapping) | ||||
| 
 | ||||
| 	docMapping.AddFieldMappingsAt("index", numberFieldMapping) | ||||
| 	docMapping.AddFieldMappingsAt("title", textFieldMapping) | ||||
| 	docMapping.AddFieldMappingsAt("content", textFieldMapping) | ||||
| 	docMapping.AddFieldMappingsAt("comments", textFieldMapping) | ||||
|  | @ -163,9 +164,15 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) ( | |||
| 		q := bleve.NewBooleanQuery() | ||||
| 		for _, token := range tokens { | ||||
| 			innerQ := bleve.NewDisjunctionQuery( | ||||
| 				inner_bleve.MatchPhraseQuery(token.Term, "title", issueIndexerAnalyzer, token.Fuzzy), | ||||
| 				inner_bleve.MatchPhraseQuery(token.Term, "content", issueIndexerAnalyzer, token.Fuzzy), | ||||
| 				inner_bleve.MatchPhraseQuery(token.Term, "comments", issueIndexerAnalyzer, token.Fuzzy)) | ||||
| 				inner_bleve.MatchPhraseQuery(token.Term, "title", issueIndexerAnalyzer, token.Fuzzy, 2.0), | ||||
| 				inner_bleve.MatchPhraseQuery(token.Term, "content", issueIndexerAnalyzer, token.Fuzzy, 1.0), | ||||
| 				inner_bleve.MatchPhraseQuery(token.Term, "comments", issueIndexerAnalyzer, token.Fuzzy, 1.0)) | ||||
| 
 | ||||
| 			if issueID, err := token.ParseIssueReference(); err == nil { | ||||
| 				idQuery := inner_bleve.NumericEqualityQuery(issueID, "index") | ||||
| 				idQuery.SetBoost(5.0) | ||||
| 				innerQ.AddQuery(idQuery) | ||||
| 			} | ||||
| 
 | ||||
| 			switch token.Kind { | ||||
| 			case internal.BoolOptMust: | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue