fergiemcdowall / norch

A search server that can be installed with npm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use JSONstream in frontend?

eklem opened this issue · comments

With previous version of Norch, I'd parse the JSON I got back from Norch and do if-checks on fields/objects or for-loops on arrays. What is the easiest way to get a stream of objects converted to an array in the browser?

On the front end you can read streams as normal (so .search works just fine), but you can't create streams natively. If you need to do indexing in your browser either use a wrapper lib like highland.js, or use .callbackyAdd

I just want to read, at least for now. Any pointers to where to start reading? I'm a little blank here, and not quite sure what to look for.

Maybe look at the code here? https://rawgit.com/fergiemcdowall/search-index/master/doc/demo/index.html

It should be as easy as doing:

mySearchIndex.search(q).on('data', function (hit) { /* render the hit somehow */ })

I need them back in an array. But you got me looking the right places, thanks!

The module I use for http get handle the response as JSON or a string. Now I do regex match for each object, and push the parsed result to an array. Works like a charm: http://oppskrift.klemespen.com/norch/