[Xapian-discuss] Node.js binding

Liam xapian at networkimprov.net
Mon Oct 17 17:52:37 BST 2011


On Fri, Oct 14, 2011 at 10:22 AM, Liam <xapian at networkimprov.net> wrote:

>
>
> On Fri, Oct 14, 2011 at 8:07 AM, Dan Colish <dcolish at gmail.com> wrote:
>
>> On Fri, Oct 14, 2011 at 4:15 AM, Richard Boulton <richard at tartarus.org
>> >wrote:
>>
>> > On 14 October 2011 10:50, Liam <xapian at networkimprov.net> wrote:
>> > > Wondering if anyone's considered/planning a Node.js binding? (I can
>> > > contribute to the effort; I have modest experience with the V8 api;
>> > though
>> > > haven't started with xapian yet.)
>> >
>> > I took a look at making one a while ago (when Node was pretty new) -
>> > actually making an extension which calls some Xapian functions from
>> > node is pretty easy to do by hand (though wrapping the full API would
>> > be harder - and I don't think SWIG has any stable V8/javascript
>> > support currently, so it would either have to be done manually or swig
>> > would have to be modified.
>> >
>> > The significant problem though is that many Xapian calls are
>> > long-running, so need to be run in a sub-thread or sub-process.  Is
>> > there any built-in support for that sort of thing in Node now? (there
>> > wasn't when I last looked).
>> >
>> > Alternatively, you could just make a client in V8 for a search server
>> > built around Xapian (eg; http://restpose.org).
>>
>>
>> I also looked into this a few months ago and I think a naive
>> implementation
>> would be easy. The issue I have is how to avoid blocking the main event
>> loop
>> in Node.js. Now that I've thought about it a bit more, I think using
>> futures
>> or promises to avoid blocking would be an alternative to just forking and
>> polling. Otherwise, I think that an API client to Restpose is a reasonable
>> solution
>>
>
> Preventing a library call from blocking Node is easy; there's a thread pool
> to which you queue with a single call. There's sample code in the project I
> linked. Typically you'd reduce trips through the thread pool during result
> iteration via a method like get_n(max, result_callback, done_callback),
> which is a little more involved.
>
> V8 doesn't support SWIG, but wrapping the entire api might not be necessary
> to get started. Extending a working module is simple.
>
> A client for Restpose, assuming it's socket-based, could be done in Node
> Javascript. That would be a decent way for me to prototype, absent a
> binding...
>

Perhaps we can define a subset of the API to implement initially in a
binding. What are the essential routines to issue a query and retrieve
results, and how are they typically used?


More information about the Xapian-discuss mailing list