mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	
							
								
								
									
										41
									
								
								vendor/github.com/blevesearch/bleve/search.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										41
									
								
								vendor/github.com/blevesearch/bleve/search.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -262,6 +262,8 @@ func (h *HighlightRequest) AddField(field string) { | ||||
| // result score explanations. | ||||
| // Sort describes the desired order for the results to be returned. | ||||
| // Score controls the kind of scoring performed | ||||
| // SearchAfter supports deep paging by providing a minimum sort key | ||||
| // SearchBefore supports deep paging by providing a maximum sort key | ||||
| // | ||||
| // A special field named "*" can be used to return all fields. | ||||
| type SearchRequest struct { | ||||
| @@ -275,6 +277,8 @@ type SearchRequest struct { | ||||
| 	Sort             search.SortOrder  `json:"sort"` | ||||
| 	IncludeLocations bool              `json:"includeLocations"` | ||||
| 	Score            string            `json:"score,omitempty"` | ||||
| 	SearchAfter      []string          `json:"search_after"` | ||||
| 	SearchBefore     []string          `json:"search_before"` | ||||
| } | ||||
|  | ||||
| func (r *SearchRequest) Validate() error { | ||||
| @@ -285,6 +289,27 @@ func (r *SearchRequest) Validate() error { | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if r.SearchAfter != nil && r.SearchBefore != nil { | ||||
| 		return fmt.Errorf("cannot use search after and search before together") | ||||
| 	} | ||||
|  | ||||
| 	if r.SearchAfter != nil { | ||||
| 		if r.From != 0 { | ||||
| 			return fmt.Errorf("cannot use search after with from !=0") | ||||
| 		} | ||||
| 		if len(r.SearchAfter) != len(r.Sort) { | ||||
| 			return fmt.Errorf("search after must have same size as sort order") | ||||
| 		} | ||||
| 	} | ||||
| 	if r.SearchBefore != nil { | ||||
| 		if r.From != 0 { | ||||
| 			return fmt.Errorf("cannot use search before with from !=0") | ||||
| 		} | ||||
| 		if len(r.SearchBefore) != len(r.Sort) { | ||||
| 			return fmt.Errorf("search before must have same size as sort order") | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return r.Facets.Validate() | ||||
| } | ||||
|  | ||||
| @@ -311,6 +336,18 @@ func (r *SearchRequest) SortByCustom(order search.SortOrder) { | ||||
| 	r.Sort = order | ||||
| } | ||||
|  | ||||
| // SetSearchAfter sets the request to skip over hits with a sort | ||||
| // value less than the provided sort after key | ||||
| func (r *SearchRequest) SetSearchAfter(after []string) { | ||||
| 	r.SearchAfter = after | ||||
| } | ||||
|  | ||||
| // SetSearchBefore sets the request to skip over hits with a sort | ||||
| // value greater than the provided sort before key | ||||
| func (r *SearchRequest) SetSearchBefore(before []string) { | ||||
| 	r.SearchBefore = before | ||||
| } | ||||
|  | ||||
| // UnmarshalJSON deserializes a JSON representation of | ||||
| // a SearchRequest | ||||
| func (r *SearchRequest) UnmarshalJSON(input []byte) error { | ||||
| @@ -325,6 +362,8 @@ func (r *SearchRequest) UnmarshalJSON(input []byte) error { | ||||
| 		Sort             []json.RawMessage `json:"sort"` | ||||
| 		IncludeLocations bool              `json:"includeLocations"` | ||||
| 		Score            string            `json:"score"` | ||||
| 		SearchAfter      []string          `json:"search_after"` | ||||
| 		SearchBefore     []string          `json:"search_before"` | ||||
| 	} | ||||
|  | ||||
| 	err := json.Unmarshal(input, &temp) | ||||
| @@ -352,6 +391,8 @@ func (r *SearchRequest) UnmarshalJSON(input []byte) error { | ||||
| 	r.Facets = temp.Facets | ||||
| 	r.IncludeLocations = temp.IncludeLocations | ||||
| 	r.Score = temp.Score | ||||
| 	r.SearchAfter = temp.SearchAfter | ||||
| 	r.SearchBefore = temp.SearchBefore | ||||
| 	r.Query, err = query.ParseQuery(temp.Q) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
|   | ||||
		Reference in New Issue
	
	Block a user