forked from go-ego/riot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Custom rating fields and rating rules | ||
=== | ||
|
||
The riot engine supports saving some rating fields in the sequencer memory and scoring documents using custom rating rules. Example: | ||
|
||
```go | ||
// Custom rating field | ||
type MyScoringFields struct { | ||
// Add some sort of document data, can be any type, such as: | ||
label string | ||
counter int32 | ||
someScore float32 | ||
} | ||
|
||
// MyScoringCriteria implements the types.ScoringCriteria interface, which is the Score function below | ||
type MyScoringCriteria struct { | ||
} | ||
func (criteria MyScoringCriteria) Score( | ||
doc types.IndexedDocument, fields interface{}) []float32 { | ||
// First check if the scoring field is of type MyScoringFields, if not, an empty slice is returned and the document is removed from the result | ||
if reflect.TypeOf(fields) != reflect.TypeOf(MySearchFields{}) { | ||
return []float32{} | ||
} | ||
|
||
// Match is type conversion | ||
myFields := fields.(MySearchFields) | ||
|
||
// The following uses the data in myFields to rate the document and return the score | ||
} | ||
``` | ||
|
||
Document MyScoringFields data through riot.Engine IndexDocument function passed to the sequencer stored in memory. Then through the Search function parameters call MyScoringCriteria query. | ||
|
||
Of course, the Score function of MyScoringCriteria can also read more document data from the hard disk or database through docId for scoring, but the speed is much slower than directly reading from memory. Please choose between memory and speed. | ||
|
||
[examples/weibo/custom_scoring_criteria.go](/examples/custom_scoring_criteria.go) contains an example of using custom rules to query Weibo data. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters