Re: IndexedDB and RegEx search

On Aug 9, 2012, at 01:39 , Jonas Sicking wrote:
> On Wed, Aug 8, 2012 at 1:33 AM, Yuval Sadan <sadan.yuval@gmail.com> wrote:
>> Perhaps it shouldn't be a full-text *index* but simply a search feature.
>> Though I'm unfamiliar with specific implementations, I gather that filtering
>> records in native code would save (possibly lots of) redundant JS object
>> construction (time and memory = money :)), and doing so with a pre-compiled
>> regex might improve over certain JS implementation or non-optimizable
>> practices, e.g.
>> function search(field, s) {
>>  someCallToIndexedDb(function filter(record) {
>>    var re = new RegExp(s);
>>    return !re.test(record[field]);
>>  }
>> }
>> 
>> Plus it saves some code jumbling for a rather common practice.
> 
> The main thing you'd save is having to round-trip between threads for
> each record. I think a more general feature that would be more
> interesting would be to be able to iterate an index or objectStore
> using a cursor, but at the time of constructing the cursor be able to
> provide a javascript function which can be used to filter the data.
> Unfortunately javascript doesn't have a good way of executing a
> function in such a way that it doesn't pull in a lot of context, but
> it's possible to hack this, for example by passing a string which
> contains the javascript code.

Actually, PhantomJS does perform some weird function decontextualisation in order to execute part of your code in a different context (that of the page you just loaded). But it's weird, surprising to developers, and ugly so I agree it's not a model to emulate.

We do, however, have Workers. It seems to me that there could be a way to make that work.

> This is somewhat similar to [1] and something we decided was
> out-of-scope for v1. But for v2 I definitely think we should look at
> mechanisms for using JS code to filter/sort/index data in such a way
> that the JS code is run on the IO thread.
> 
> [1] https://www.w3.org/Bugs/Public/show_bug.cgi?id=10000

There's a lot of excellent prior art in CouchDB for what you're describing in that bug (or at least parts thereof). I think it's well worth looking at.

-- 
Robin Berjon - http://berjon.com/ - @robinberjon

Received on Thursday, 9 August 2012 12:29:14 UTC