Comments (4)
@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.
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.
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.
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)
- Python bindings
- Enhancement: add new method GetWithTTL to return value together with TTL
- What happens if two funcs write to the db at the exact same time? HOT 1
- Get size of db on disk
- Does the data.db file support rewrite like redis AOF? HOT 2
- Dependencies update due?
- Feature Request: Delete inside iterator
- Question: cost/benefit of supporting generic types; and persisting secondary indexes
- Questing about extra index
- don't understand example HOT 1
- index, or getting with different keys doesn't work HOT 1
- tx.Ascend doesn't work correctly HOT 1
- Does buntdb needs Go 1.18+ due to btree dependency? HOT 1
- Question: What is the format of .db file? HOT 1
- I wonder if we can find closest lat long for a given latlon from spatial index using nearby
- [Feature Request] Is there a way to limit memroy usage?
- Is there any plan to support index on MessagePack? HOT 1
- How to renew the ttl?
- Question: Is buntdb goroutine-safe? HOT 1
- Will "group by" be supported in this lib?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from buntdb.