H i Erik,
As soon asw I add .withOptions() to my query I got tis Error:
My roter respone function:
router.post('/search', function (req, res) {
try {
db.documents.query(
qb.where(
qb.collection("housedata"),
qb.parsedFrom(req.body.SearchString))
.orderBy(qb.sort(qb.score(), "descending"))
.withOptions({ categories: 'none' })
)
.result(function (documents) {
documents.forEach(function (document) {
console.log(document.content.name + " at " + document.uri);
})
res.render('index', { title: 'MVSearch', results : documents });
res.end();
}, function (error) {
console.dir(error);
res.render('index', { title: 'MVSearch', error : error });
res.end();
});
}
catch (e) {
res.render('index', { title: 'MVSearch', session : req.session, exp
: e });
console.log(e);
}
});
And the error:
E:\Git\ExpressTest\node_modules\marklogic\node_modules\bluebird\js\main\asyn
c.js
:43
fn = function () { throw arg; };
^
TypeError: Cannot read property 'name' of undefined
at E:\Git\ExpressTest\routes\index.js:40:41
at Array.forEach (native)
at E:\Git\ExpressTest\routes\index.js:39:19
at tryCatcher
(E:\Git\ExpressTest\node_modules\marklogic\node_modules\bluebi
rd\js\main\util.js:24:31)
at Promise.module.exports.Promise._settlePromiseFromHandler
(E:\Git\ExpressT
est\node_modules\marklogic\node_modules\bluebird\js\main\promise.js:454:31)
at Promise.module.exports.Promise._settlePromiseAt
(E:\Git\ExpressTest\node_
modules\marklogic\node_modules\bluebird\js\main\promise.js:530:18)
at Promise.module.exports.Promise._settlePromises
(E:\Git\ExpressTest\node_m
odules\marklogic\node_modules\bluebird\js\main\promise.js:646:14)
at Async._drainQueue
(E:\Git\ExpressTest\node_modules\marklogic\node_modules
\bluebird\js\main\async.js:177:16)
at Async._drainQueues
(E:\Git\ExpressTest\node_modules\marklogic\node_module
s\bluebird\js\main\async.js:187:10)
at Immediate.drainQueues [as _onImmediate]
(E:\Git\ExpressTest\node_modules\
marklogic\node_modules\bluebird\js\main\async.js:15:14)
at processImmediate [as _immediateCallback] (timers.js:358:17)
Any hints are very welcome!
Martin
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Erik Hennum
Gesendet: Sonntag, 7. Juni 2015 20:20
An: MarkLogic Developer Discussion
Betreff: Re: [MarkLogic Dev General] sort by relevance with querybuilder in
node.js
Hi, Martin:
The score() function declares sorting by relevance by default, so you
shouldn't have to supply any argument to score.
By default documents.query() returns the documents.
If you want to return only a report with the document scores and not the
documents, you can use the withOptions clause, as in:
.withOptions({categories:'none'})
The score() function should be passing the score method. As a workaround,
you can set the score method using the search options key with the
withOptions clause, as in:
.withOptions({search:['score-random']})
Hoping that helps,
Erik Hennum
_____
From: [email protected]
<mailto:[email protected]>
[[email protected]] on behalf of Martin Vollmix
[[email protected]]
Sent: Sunday, June 07, 2015 8:17 AM
To: 'MarkLogic Developer Discussion'
Subject: [MarkLogic Dev General] sort by relevance with querybuilder in
node.js
Hi,
I am trying to create a query using relevance with querybuilder in node.js
My first attempt looks like this:
db.documents.query(
q.where(
q.collection("housedata"),
q.parsedFrom(req.body.SearchString))
.orderBy(q.sort(q.score("random"), "descending")
)
)
But this results in an error:
{ [Error: query documents: response with invalid 400 status]
message: 'query documents: response with invalid 400 status',
statusCode: 400,
body:
{ errorResponse:
{ statusCode: 400,
status: 'Bad Request',
messageCode: 'REST-INVALIDPARAM',
message: 'REST-INVALIDPARAM: (err:FOER0000) Invalid parameter:
Invalid combined search\nRESTAPI-INVALIDCONTENT: (err:FOER0000) Invalid
content: Operation
results in invalid Options: XDMP-VALIDATEUNEXPECTED: (err:XQDY0027) validate
strict { $opt } -- Invalid node: Found text{"random..."} but expected ()
at /search:search/search:options/search:sort-order/search:score/text() using
schema
"search.xsd"text{"random..."}()/search:search/search:options/search:sort-ord
er/search:score/text()"search.xsd"' } } }
If I use score() with no argument it is working, bur no ranking info is
returned.
Can anybody help me out?
Thanks in advance !
Martin Vollmer
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general