Sortby decay funtions#2036
Merged
Merged
Conversation
kishorenc
approved these changes
Oct 29, 2024
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Summary
Decay Functions
Decay functions supplied with sortby params provides functionality to simulate gaussian, linear, and exponential curve behavior and scores the results accordingly.
Usage
Decay functions are used with sortby params and syntax for same can be found below,
Here,
timestampis the sort field to be searched,originis the pivot point from where the curve will originate as per paramfuncis the decay function name. Currently Typesense supports onlygauss,linear,exp, anddifffunctions.scaleis non zero integral value by which decay will be appliedoffsetis the value from which origin point will be offsetteddecayis the the rate between [0.0,1.0] at which scores will be decayed.originandscaleare mandatory params withfuncname.decay value if not supplied is defaulted to
0.5Example
Let's assume following schema,
{ "name": "products", "fields":[ {"name": "product_name","type": "string"}, {"name": "timestamp","type": "int64"} ] }with the records,
{"product_name": "Samsung Smartphone", "timestamp": 1728383250} {"product_name": "Vivo Smartphone", "timestamp": 1728384250} {"product_name": "Oneplus Smartphone", "timestamp": 1728385250} {"product_name": "Pixel Smartphone", "timestamp": 1728386250} {"product_name": "Moto Smartphone", "timestamp": 1728387250}Now we will search with following query
we will get response as below,
{"hits":[{"document":{"id":"2","product_name":"Oneplus Smartphone","timestamp":1728385250}},{"document":{"id":"3","product_name":"Pixel Smartphone","timestamp":1728386250}},{"document":{"id":"1","product_name":"Vivo SmartPhone","timestamp":1728384250}},{"document":{"id":"4","product_name":"Moto Smartphone","timestamp":1728387250}},{"document":{"id":"0","product_name":"Samsung Smartphone","timestamp":1728383250}}]}Here, we've supplied origin point
1728385250so it'll get highest score(viz 1.0). Later at every scale value interval (viz 1000), score get reduced by decay value (viz 0.5) and accordingly results are sorted.PR Checklist