range queries on numbers
See original GitHub issueI know it’s out of the scope but would be really happy to have it in lunr 😃
var index = lunr(function(){
this.field('price');
this.ref('id');
});
index.add({id: "1",price: "2"});
index.add({id: "2",price: "11"});
index.add({id: "3",price: "27"});
var results = index.numericRangeSearch("[10:30]");
// results = {id : 2 , id : 3}
Lucene used to transform numbers to sortable strings to achieve such kinds of queries : https://github.com/apache/lucene-solr/blob/master/lucene/core/src/java/org/apache/lucene/util/NumericUtils.java
And some times before, the workaround was to use padding : Before
2
11
27
After
002
011
027
If you don’t want to include this feature in lunr, any help would be really appreciated.
Thanks a lot for this wonderful project anyway.
Manu
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Range query (data structures) - Wikipedia
In data structures, a range query consists of preprocessing some input data into a data structure to efficiently answer any number of queries...
Read more >Range Queries to count elements lying in a given Range
Given an array arr[] of N elements and two integers A to B, the task is to answer Q queries each having two...
Read more >Linear Range Queries
A range query consists of giving a range, such as in interval in a line, a square or other region in a plane;...
Read more >ArangoSearch Range Query Examples - ArangoDB
The primary use case for range queries is to search numeric values in documents ... to a reference number, or; between two numbers...
Read more >The Mostly repeated number in range query - Codeforces
given an array of integers with (N <= 1e6) and Q (Q <= 1e6) queries with L and R.. what is the mostly...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So, first of all, this is almost definitely not going to make it into the current version of lunr, it would involve too much change, specifically around understanding the search term, but probably in other places too.
The next version of lunr already has some smarts around parsing search queries, so there is already the pieces in place for understanding
[10:30]
as meaning any document with a number between 10 and 30.I need to do a bit more background reading, as well as consider how text ranges such as
[aa:ab]
would work, but it might be something that could end up making it into lunr.I’ll keep this issue open for now, just to remind me to think about it. I can’t promise that I’ll end up with a solution any time soon though.
@fauno not yet, mostly because I haven’t prioritised it.