{"id":1560,"date":"2018-05-03T14:25:12","date_gmt":"2018-05-03T14:25:12","guid":{"rendered":"http:\/\/capture.ccio.us\/?p=1560"},"modified":"2018-05-03T14:25:12","modified_gmt":"2018-05-03T14:25:12","slug":"overriding-query-pipeline-pt-iii","status":"publish","type":"post","link":"https:\/\/capture.club\/portal\/2018\/05\/03\/overriding-query-pipeline-pt-iii\/","title":{"rendered":"Overriding the Query Pipeline, Pt III"},"content":{"rendered":"<body><p><\/p><img decoding=\"async\" class=\"alignnone size-full wp-image-1462\" src=\"http:\/\/capture.ccio.us\/wp-content\/uploads\/2018\/05\/Data-Pipeline.jpg\" alt=\"data-pipeline\" width=\"405\" height=\"228\" loading=\"lazy\"><br>\nWhen we last left our rogue query pipeline in <a href=\"http:\/\/capture.ccio.us\/overriding-query-pipeline-pt-ii\/\">Pt II<\/a>, we had made our Solr query and had tucked the response into a JSON object.\u00a0 This call was made from our \u201cmain\u201d function, which is incidentally the last function \u2014 an anonymous function \u2014 declared at the end of your stage.\u00a0 For example:\n<pre>  function doFoo(){\n  }\n  funciton Bar(){\n    return doFoo();\n  }\n  funtion(){\n      var bar = new Bar();\n   }\n<\/pre>\n<p>In the above example, the only function called directly by Fusion is the anonymous function at the end, but moving on.<br>\nThus we have our documents in hand. Let\u2019s do something with them now:<\/p>\n<pre>    \/\/ make the Solr query call:\n    var docs = doHttpQuery(request);\n    \/\/ get the result, returns type ConString\n    var result = docs.get(\"result\");\n    \/\/ create a JSON object using the Nashorn parser.\n    var resultJson = JSON.parse(result.toString());\n    \/\/ this is your docs array that you'll modify and load back into the request.\n    var jsonDocs = resultJson.response.docs;\n   \/\/ loop through the docs and make whatever changes.\n    for(var i=0; i<jsondocs.length i jsondoc add the docs to our result. json.put json.stringify var someobject=\"new\" java.lang.string json.tostring stream=\"new\" java.io.bytearrayinputstream v2=\"new\" com.lucidworks.apollo.solr.response.rawresponse send response. if we wanted headers replace null arg with a map. newresponse=\"new\" com.lucidworks.apollo.pipeline.query.response queryrequestandresponse=\"com.lucidworks.apollo.pipeline.query.QueryRequestAndResponse.create(request,\" return>\n    And, Viola! We have successfully made an asynchrouns REST query call, modified the result, and set that result on along down the pipeline.\n    The query pipeline override is a powerful tool, but as with any significant hack, you should use it wisely.  Mis-use or over-use can cause performance trouble.  With great power comes great responsibility. Always use Best Practices, and don't go hog wild.  JavaScript stages are powerful tools, but need to be used in moderation.\n    Happy Searching! <\/jsondocs.length><\/pre>\n<p><\/p>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>When we last left our rogue query pipeline in Pt II, we had made our Solr query and had tucked the response into a JSON object.\u00a0 This call was made from our \u201cmain\u201d function, which is incidentally the last function \u2014 an anonymous function \u2014 declared at the end of your stage.\u00a0 For example: function [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[],"tags":[],"class_list":["post-1560","post","type-post","status-publish","format-standard","hentry"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/capture.club\/portal\/wp-json\/wp\/v2\/posts\/1560","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/capture.club\/portal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/capture.club\/portal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/capture.club\/portal\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/capture.club\/portal\/wp-json\/wp\/v2\/comments?post=1560"}],"version-history":[{"count":0,"href":"https:\/\/capture.club\/portal\/wp-json\/wp\/v2\/posts\/1560\/revisions"}],"wp:attachment":[{"href":"https:\/\/capture.club\/portal\/wp-json\/wp\/v2\/media?parent=1560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/capture.club\/portal\/wp-json\/wp\/v2\/categories?post=1560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/capture.club\/portal\/wp-json\/wp\/v2\/tags?post=1560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}