norch icon indicating copy to clipboard operation
norch copied to clipboard

Documentation: Autocomplete / matcher from the browser with Opensearch

Open eklem opened this issue 9 years ago • 11 comments

So, gotten Opensearch.xml to work with the browser search box over at life-index, but need a little more to get the autocomplete to work fully.

Today the respons JSON is an array of suggested search words. skjermbilde 2015-05-23 kl 21 52 30

From the Opensearch XML documentation for suggestions it seems I need to alter the JSON a bit. I need the existing list

[  
   "test",
   "testing",
   "tests",
   "tested",
   "test2"",
   "test2",
   "test\\tools\\bench",
   "testcase",
   "test1"",
   "testdata"
]

to look like

[  
   "test",
   [  
      "test",
      "testing",
      "tests",
      "tested",
      "test2"",
      "test2",
      "test\\tools\\bench",
      "testcase",
      "test1"",
      "testdata"
   ]
]

Where the first array consists of the query or beginsWith and then the array of suggestions. My question is if you have an idea on how easy it would be to make this a part of the existing Norch without breaking anything?

Before you do anything, I can test with some dummy-JSON to be sure this is actually working for the browser.

eklem avatar May 23 '15 20:05 eklem

Ok, tested it with a static suggestions-file. And it works! skjermbilde 2015-05-23 kl 22 32 10

The browser needs the query or beginsWith back from the matcher in order to list out the autocomplete. But great news =)

The suggestions-file contained this JSON:

[  
   "test",
   [  
      "test",
      "testing",
      "tests",
      "tested",
      "test2"",
      "test2",
      "test\\tools\\bench",
      "testcase",
      "test1"",
      "testdata"
   ]
]

And it kicked in when I had typed test.

eklem avatar May 23 '15 20:05 eklem

Got it working! Do you want a pull request? Small change, or actually addition, in norch.js:

The old matcher is like this:

  this.app.get('/matcher', function(req, res) {
    that.si.match(req.query['beginsWith'], function(err, matches) {
      res.send(matches);
    });
  });

The Opensearch suggestions like this (addition):

  this.app.get('/opensearchsuggests', function(req, res) {
    that.si.match(req.query['beginsWith'], function(err, matches) {
      res.send([req.query.beginsWith, matches]);
    });
  });

Screendumps from test: skjermbilde 2015-05-24 kl 12 31 10

skjermbilde 2015-05-24 kl 12 31 27

eklem avatar May 24 '15 10:05 eklem

@eklem did you ever make that PR, or have any code that is PRable? :)

fergiemcdowall avatar Aug 21 '15 08:08 fergiemcdowall

Haven't made it. It's slightly hackish, but I think it's a good first step to add it, and then make it better. I'll do a PR, and you can decide to use it or not.

eklem avatar Aug 21 '15 11:08 eklem

OK! :)

fergiemcdowall avatar Aug 21 '15 16:08 fergiemcdowall

Not getting it to work in Mozilla anymore, so have to investigate a little.

eklem avatar Aug 28 '15 11:08 eklem

Ahh- the matcher API has changed ever-so-slightly, a call to the matcher now looks like this: http://localhost:3030/matcher?match={"beginsWith":"usa"}

There are also a few extra options- see the search-index docs for more info

fergiemcdowall avatar Aug 28 '15 13:08 fergiemcdowall

I'm still on an old version, so that shouldn't matter. It stopped working on Mozilla for Android, but desktop is fine.

eklem avatar Aug 30 '15 06:08 eklem

But, I'll leave the Android version for now and try adding the stuff needed.

eklem avatar Aug 30 '15 06:08 eklem

This is a great usecase for creating a query-result pipeline

fergiemcdowall avatar Nov 11 '16 12:11 fergiemcdowall

Another query-pipeline case is #124

fergiemcdowall avatar Jan 09 '17 13:01 fergiemcdowall