norch
norch copied to clipboard
Documentation: Autocomplete / matcher from the browser with Opensearch
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.
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.
Ok, tested it with a static suggestions-file. And it works!
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
.
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:
@eklem did you ever make that PR, or have any code that is PRable? :)
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.
OK! :)
Not getting it to work in Mozilla anymore, so have to investigate a little.
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
I'm still on an old version, so that shouldn't matter. It stopped working on Mozilla for Android, but desktop is fine.
But, I'll leave the Android version for now and try adding the stuff needed.
This is a great usecase for creating a query-result pipeline
Another query-pipeline case is #124