Giter Club home page Giter Club logo

Comments (4)

abhinavdangeti avatar abhinavdangeti commented on June 7, 2024

Multiple sort keys come in handy when some of the document hits are missing or equal sort values for earlier keys.

Here is an example test case that could help -
https://github.com/blevesearch/bleve/blob/v2.3.7/examples_test.go#L443

from bleve.

elektito avatar elektito commented on June 7, 2024

This doesn't seem to be quite what I was looking for. As far as I can tell, it's sorting only based on age while what I was looking for is something like sorting by the multiplication product of two relevance score and a field in the document. FWIW, I finally came up with this, which seems to work:

func (so *RankedSort) UpdateVisitor(field string, term []byte) {
	switch field {
	case "pRank":
		if len(term) > len(so.pRank) {
			so.pRank = make([]byte, len(term))
			copy(so.pRank, term)
		}
	case "hRank":
		if len(term) > len(so.hRank) {
			so.hRank = make([]byte, len(term))
			copy(so.hRank, term)
		}
	}
}

func (so *RankedSort) Value(a *search.DocumentMatch) string {
	prp, _ := numeric.PrefixCoded(so.pRank).Int64()
	pr := math.Float64frombits(uint64(prp))

	hrp, _ := numeric.PrefixCoded(so.hRank).Int64()
	hr := math.Float64frombits(uint64(hrp))

	so.pRank = so.pRank[:0]
	so.hRank = so.hRank[:0]

	score := numeric.Float64ToInt64((a.Score + 1) * (pr + 1) * (hr + 1))

	return string(numeric.MustNewPrefixCodedInt64(score, 0))
}

(I'm pretty sure how I use the absolute value of score and multiply it by other values is technically incorrect, since the score value does not have any bounds that I'm aware of; would love any suggestions on that front too.)

from bleve.

abhinavdangeti avatar abhinavdangeti commented on June 7, 2024

Ah I see, for custom sorting - we've provided an API for the SearchRequest that you could leverage. I suppose you're registering your RankedSort using this -
https://github.com/blevesearch/bleve/blob/v2.3.7/search.go#L629

The internal score determination is based on the tf-idf algorithm. Boosting is the only way we allow users to adjust/influence this score generated for your document hits.

from bleve.

elektito avatar elektito commented on June 7, 2024

I'm using SortByCustom. I didn't know about SetSortFunc. Looks like it's more concerned with the implementation of sort, than scoring, or did I get that wrong?

Are you saying that what I'm doing is borderline unsupported? Boost it is not gonna work for my use case, because I want the scores to come partially from relevance, and partially by the rank of each item. This is a small search engine, and pRank is actually PageRank; the score*rank multiplication was the best I could come up with to achieve what I wanted. It does seem to be working mostly. I just don't like that I'm multiplying by score, which I don't know the dimensions or bounds of, and indeed I think I read somewhere it's not even meant to be comparable between different searches.

from bleve.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.