Git Product home page Git Product logo

Comments (4)

tmazeika avatar tmazeika commented on July 17, 2024 1

@haasted I came up with a similar solution to your IndexJSONOptional and I think that it should be fine. But given my brief experiments, it looks like it only works when all optional indices appear last in the multi-index list. I wouldn't really be able to say exactly why, though.

from buntdb.

haasted avatar haasted commented on July 17, 2024

Worked a bit more and realized the following (which I perhaps should have caught earlier): Removing the second index makes the AscendEqual work as expected. Alternatively, including the age field in the search term also yields results.

Is there some way to make AscendEqual treat an omitted field in the search term as "wildcard", ie. I do not care about this value?

from buntdb.

tidwall avatar tidwall commented on July 17, 2024

Is there some way to make AscendEqual treat an omitted field in the search term as "wildcard", ie. I do not care about this value?

I don’t think that that is possible with AscendEqual. It’s meant to grab exact matches.

One idea is to use AscendGreaterOrEqual, which will jump you to the first candidate. Then, from inside the iteration function, do a custom comparison on each item, and then break out of the iterator once you encounter an item that moves outside the range of possibilities.

This is basically how the AscendEquals works. It uses AscendGreaterOrEquals in the hood, and it’s comparison is looking for an exact match.

from buntdb.

haasted avatar haasted commented on July 17, 2024

Thanks for the prompt and helpful reply. Definitely the solution to use.

Just for fun, I also tried to implement an "optional" JSON index, which will not match in case any of the JSON paths offered do not exist. Using that does actually seem to have solved my issue, although I'm not completely sure that I haven't violated the contract of the comparison function in the most obscene way possible or missed some test cases that will break functionality. :)

func IndexJSONOptional(path string) func(a, b string) bool {
	return func(a, b string) bool {
		opa := gjson.Get(a, path)
		opb := gjson.Get(b, path)

		if !opa.Exists() || !opb.Exists() {
			return false
		}

		return opa.Less(opb, false)
	}
}

from buntdb.

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.