question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

range queries on numbers

See original GitHub issue

I 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:open
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
olivernncommented, Oct 31, 2016

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.

0reactions
olivernncommented, Jul 22, 2018

@fauno not yet, mostly because I haven’t prioritised it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found