From c23c50b3b79a59b6781dfb980b596a9411328f2e Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Thu, 25 Aug 2016 18:30:52 -0700 Subject: [PATCH 01/16] started work on recommenders --- client/assets/components/components.js | 3 ++- .../components/documentList/documentList.html | 1 + .../assets/components/documentList/documentList.js | 4 ++++ .../components/facetField/facetFieldDirective.js | 1 + client/assets/js/controllers/HomeController.js | 14 ++++++++++++++ client/assets/js/services/URLService.js | 1 + client/templates/home.html | 4 ++-- 7 files changed, 25 insertions(+), 3 deletions(-) diff --git a/client/assets/components/components.js b/client/assets/components/components.js index b27aa890..5d014aee 100644 --- a/client/assets/components/components.js +++ b/client/assets/components/components.js @@ -14,5 +14,6 @@ angular.module('lucidworksView.components', [ 'lucidworksView.components.login', 'lucidworksView.components.paginate', 'lucidworksView.components.searchbox', - 'lucidworksView.components.sort' + 'lucidworksView.components.sort', + 'lucidworksView.components.recommendations' ]); diff --git a/client/assets/components/documentList/documentList.html b/client/assets/components/documentList/documentList.html index 49e06c4e..1a4fe911 100644 --- a/client/assets/components/documentList/documentList.html +++ b/client/assets/components/documentList/documentList.html @@ -1,5 +1,6 @@
+ click for related items! diff --git a/client/assets/components/documentList/documentList.js b/client/assets/components/documentList/documentList.js index 79dc266c..c164ee5e 100644 --- a/client/assets/components/documentList/documentList.js +++ b/client/assets/components/documentList/documentList.js @@ -142,5 +142,9 @@ function getDocPosition(doc, docs){ return _.findIndex(docs, doc); } + + function getRelatedItems(doc) { + console.log("Find related items here!"); + } } })(); diff --git a/client/assets/components/facetField/facetFieldDirective.js b/client/assets/components/facetField/facetFieldDirective.js index 7d20cdeb..38eb4105 100644 --- a/client/assets/components/facetField/facetFieldDirective.js +++ b/client/assets/components/facetField/facetFieldDirective.js @@ -6,6 +6,7 @@ .directive('facetField', facetField); function facetField() { + console.log("In the facetfield constructor"); 'ngInject'; return { restrict: 'EA', diff --git a/client/assets/js/controllers/HomeController.js b/client/assets/js/controllers/HomeController.js index 79da403c..33dc29c2 100644 --- a/client/assets/js/controllers/HomeController.js +++ b/client/assets/js/controllers/HomeController.js @@ -32,6 +32,10 @@ hc.sorting = {}; hc.grouped = false; + // Recommendations Logic + // hc.hasId = false; + hc.showRecommendations = false; + query = URLService.getQueryFromUrl(); //Setting the query object... also populating the the view model hc.searchQuery = _.get(query,'q','*'); @@ -46,6 +50,8 @@ sorting.switchSort = switchSort; createSortList(); + // Get the recommendations + checkRecommendations(data); }); // Force set the query object to change one digest cycle later @@ -56,6 +62,14 @@ }); } + function checkRecommendations(data) { + // console.log("In the check recommendations portion of the home controller!"); + if (data.hasOwnProperty('moreLikeThis')){ + console.log("We have more like this!! Set the home controller to true"); + hc.showRecommendations = true; + } + } + function checkResultsType(data){ if (data.hasOwnProperty('response')) { hc.numFound = data.response.numFound; diff --git a/client/assets/js/services/URLService.js b/client/assets/js/services/URLService.js index ff0e3e4c..bfc71cf8 100644 --- a/client/assets/js/services/URLService.js +++ b/client/assets/js/services/URLService.js @@ -42,6 +42,7 @@ $state.go('home', newStateObject, {notify: false, reloadOnSearch: false}); } + /** * Gets query object from URL */ diff --git a/client/templates/home.html b/client/templates/home.html index 22efbdc0..5e3f836e 100644 --- a/client/templates/home.html +++ b/client/templates/home.html @@ -81,8 +81,8 @@
- -
+
+
From 20b2e2890399014719cf7cfdad200ab342c117a1 Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Thu, 25 Aug 2016 18:32:20 -0700 Subject: [PATCH 02/16] started work on recommendations --- .../recommendations/recommendations.html | 32 +++++++++++ .../recommendations/recommendations.js | 54 +++++++++++++++++++ .../recommendations/recommendations.scss | 4 ++ 3 files changed, 90 insertions(+) create mode 100644 client/assets/components/recommendations/recommendations.html create mode 100644 client/assets/components/recommendations/recommendations.js create mode 100644 client/assets/components/recommendations/recommendations.scss diff --git a/client/assets/components/recommendations/recommendations.html b/client/assets/components/recommendations/recommendations.html new file mode 100644 index 00000000..c911d0fd --- /dev/null +++ b/client/assets/components/recommendations/recommendations.html @@ -0,0 +1,32 @@ +
+

Recommendations

+ +
+

More Like This

+
+
+ + +
+ +
+ +
+
+ + +
+
+ +
+
+
+
diff --git a/client/assets/components/recommendations/recommendations.js b/client/assets/components/recommendations/recommendations.js new file mode 100644 index 00000000..cc63dc5b --- /dev/null +++ b/client/assets/components/recommendations/recommendations.js @@ -0,0 +1,54 @@ +(function () { + 'use strict'; + angular + .module('lucidworksView.components.recommendations', [ + 'lucidworksView.services', + 'angucomplete-alt', + 'angular-humanize' + ]) + .directive('recommendations', recommendations); + + function recommendations() { + 'ngInject'; + + return { + restrict: 'EA', + templateUrl: 'assets/components/recommendations/recommendations.html', + controller: Controller, + controllerAs: 'rc', + bindToController: {}, + scope: true, + replace: true + }; + } + + function Controller(Orwell, $log) { + console.log("In the controller for the recommendations js stage"); + 'ngInject'; + var rc = this; //eslint-disable-line + rc.mltDocs = []; + rc.cfDocs = []; + rc.preCFDocs = []; + activate(); + + function activate() { + var resultsObservable = Orwell.getObservable('queryResults'); + resultsObservable.addObserver(function(data) { + // Get the recommendations + checkRecommendations(data); + }); + + function checkRecommendations(data) { + // console.log("In the check recommendations portion of the home controller!"); + if (data.hasOwnProperty('moreLikeThis')){ + console.log("We have more like this! Let's populate the rc"); + for (var key in data.moreLikeThis) { + rc.mltDocs.push(data.moreLikeThis[key].docs); + } + console.log(rc.mltDocs); + } + } + + } + } +})(); diff --git a/client/assets/components/recommendations/recommendations.scss b/client/assets/components/recommendations/recommendations.scss new file mode 100644 index 00000000..b3b05c48 --- /dev/null +++ b/client/assets/components/recommendations/recommendations.scss @@ -0,0 +1,4 @@ +.recHeader{ + padding-top: 10px; + padding-bottom: 10px; +} \ No newline at end of file From 95ccb613b5c7d06546eb31004d0f73204c246c52 Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Tue, 30 Aug 2016 10:24:44 -0700 Subject: [PATCH 03/16] Implemented two methods of querying solr using MLT, One default search and one using a pipeline and a workaround to only launch the search upon request. The second method is currently very slow --- .../components/documentList/documentList.html | 4 +- .../components/documentList/documentList.js | 53 ++++++++++++++++++- .../recommendations/recommendations.js | 16 +++--- client/assets/js/services/ConfigService.js | 5 ++ client/assets/js/services/QueryDataService.js | 44 ++++++++++++++- 5 files changed, 110 insertions(+), 12 deletions(-) diff --git a/client/assets/components/documentList/documentList.html b/client/assets/components/documentList/documentList.html index 1a4fe911..a0d2f227 100644 --- a/client/assets/components/documentList/documentList.html +++ b/client/assets/components/documentList/documentList.html @@ -1,7 +1,9 @@
- click for related items! + Related Items + click here to launch! + diff --git a/client/assets/components/documentList/documentList.js b/client/assets/components/documentList/documentList.js index c164ee5e..c44a4979 100644 --- a/client/assets/components/documentList/documentList.js +++ b/client/assets/components/documentList/documentList.js @@ -21,7 +21,7 @@ } - function Controller($sce, $log, $anchorScroll, Orwell) { + function Controller($sce, $log, $anchorScroll, Orwell, QueryDataService) { 'ngInject'; var vm = this; vm.docs = []; @@ -31,6 +31,10 @@ vm.toggleGroupedResults = toggleGroupedResults; vm.showGroupedResults = {}; vm.getDocPosition = getDocPosition; + vm.getRelatedItems = getRelatedItems; + vm.launchMlt = launchMlt; + + activate(); @@ -144,7 +148,52 @@ } function getRelatedItems(doc) { - console.log("Find related items here!"); + // There are two ways of doing this, the first is by getting the MLT results and checking against the + // document name using the general MLT stage (this is slower because it loads mlt for every document thus + // slowing the inital search. + console.log("Find related items here by querying solr correctly!"); + var resultsObservable = Orwell.getObservable('queryResults'); + var docs; + var finalList = []; + + if (resultsObservable.content.moreLikeThis != null) { + console.log("Inside the getRelatedItems!"); + console.log(resultsObservable.content.moreLikeThis); + for (var item in resultsObservable.content.moreLikeThis) { + if (item == doc.id) { + docs = resultsObservable.content.moreLikeThis[item].docs; + break; + } + } + } + if (docs != undefined) { + if (docs.length == 0) { + return "No Related Items Found!" + } + else { + for (var doc in docs){ + finalList.push(docs[doc].title); + } + } + return finalList; + } } + + function launchMlt(doc) { + console.log("launching mlt"); + console.log(doc.id); + vm.id = doc.id + + QueryDataService.getMltQueryResults({q: "id:" + vm.id, wt: 'json'}).then(manipulate_mlt); + + function manipulate_mlt(response){ + console.log("Done getting the stuff"); + console.log(vm.id); + var mltResults = Orwell.getObservable('mltResults').content[vm.id].docs; + return mltResults; + } + + } + } })(); diff --git a/client/assets/components/recommendations/recommendations.js b/client/assets/components/recommendations/recommendations.js index cc63dc5b..3602ab99 100644 --- a/client/assets/components/recommendations/recommendations.js +++ b/client/assets/components/recommendations/recommendations.js @@ -38,16 +38,16 @@ checkRecommendations(data); }); - function checkRecommendations(data) { - // console.log("In the check recommendations portion of the home controller!"); - if (data.hasOwnProperty('moreLikeThis')){ - console.log("We have more like this! Let's populate the rc"); - for (var key in data.moreLikeThis) { - rc.mltDocs.push(data.moreLikeThis[key].docs); - } - console.log(rc.mltDocs); + function checkRecommendations(data) { + // console.log("In the check recommendations portion of the home controller!"); + if (data.hasOwnProperty('moreLikeThis')){ + console.log("We have more like this! Let's populate the rc"); + for (var key in data.moreLikeThis) { + rc.mltDocs.push(data.moreLikeThis[key].docs); } + console.log(rc.mltDocs); } + } } } diff --git a/client/assets/js/services/ConfigService.js b/client/assets/js/services/ConfigService.js index 609d4401..8f2e7093 100644 --- a/client/assets/js/services/ConfigService.js +++ b/client/assets/js/services/ConfigService.js @@ -79,6 +79,7 @@ getQueryProfile: getQueryProfile, getCollectionName: getCollectionName, getQueryPipeline: getQueryPipeline, + getMltPipeline: getMltPipeline, getLoginCredentials: getLoginCredentials, getIfQueryProfile: getIfQueryProfile, getFieldLabels: getFieldLabels, @@ -123,6 +124,10 @@ return appConfig.query_pipeline_id; } + function getMltPipeline() { + return appConfig.recommender_pipeline_id; + } + function getQueryProfile() { return appConfig.query_profile_id; } diff --git a/client/assets/js/services/QueryDataService.js b/client/assets/js/services/QueryDataService.js index 4c113f98..fb5c8f2f 100644 --- a/client/assets/js/services/QueryDataService.js +++ b/client/assets/js/services/QueryDataService.js @@ -13,6 +13,7 @@ function Config(OrwellProvider) { 'ngInject'; OrwellProvider.createObservable('queryResults', {}); + OrwellProvider.createObservable('mltResults', {poop:"poop"}); } function QueryDataService() { @@ -24,10 +25,13 @@ function $get($q, $http, ConfigService, ApiBase, Orwell, QueryBuilder) { 'ngInject'; var queryResultsObservable = Orwell.getObservable('queryResults'); + var mltResultsObservable = Orwell.getObservable('mltResults'); return { getQueryResults: getQueryResults, getProfileEndpoint: getProfileEndpoint, - getPipelineEndpoint: getPipelineEndpoint + getPipelineEndpoint: getPipelineEndpoint, + getMltQueryResults: getMltQueryResults, + getMltQueryUrl: getMltQueryUrl }; /** @@ -42,7 +46,9 @@ var queryString = QueryBuilder.objectToURLString(query); + console.log("In getqueryresults and trying to access mlt pipeline"); var fullUrl = getQueryUrl(ConfigService.getIfQueryProfile()) + '?' + queryString; + console.log(fullUrl); $http .get(fullUrl) @@ -50,6 +56,8 @@ .catch(failure); function success(response) { + console.log("Success!!!! getting response"); + console.log(response); // Set the content to populate the rest of the ui. queryResultsObservable.setContent(response.data); deferred.resolve(response.data); @@ -65,6 +73,35 @@ return deferred.promise; } + + function getMltQueryResults(query, id) { + var deferred = $q.defer(); + + var queryString = QueryBuilder.objectToURLString(query); + + var fullUrl = getMltQueryUrl() + '?' + queryString; + console.log('urllll', fullUrl); + + $http + .get(fullUrl) + .then(success) + .catch(failure); + + function success(response) { + console.log('responseeee', response.data.moreLikeThis); + mltResultsObservable.setContent(response.data.moreLikeThis); + deferred.resolve(response.data.moreLikeThis); + } + + function failure(err) { + mltResultsObservable.setContent({ + numFound: 0 + }); + deferred.reject(err.data); + } + return deferred.promise; + } + /** * Returns the appropriate base url for an endpoint * @@ -90,6 +127,11 @@ '/' + requestHandler; } + function getMltQueryUrl(){ + var pipelinesEndpoint = getPipelineEndpoint(ConfigService.getMltPipeline(), 'select'); + return pipelinesEndpoint; + } + } } })(); From 2acb4c46d50a14a794d50ff2eb8aa6a53c1219c1 Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Tue, 30 Aug 2016 13:18:17 -0700 Subject: [PATCH 04/16] cleaned up some code --- .../components/documentList/documentList.html | 6 ++- .../components/documentList/documentList.js | 52 ++++++++++--------- client/assets/js/services/ConfigService.js | 1 - client/assets/js/services/QueryDataService.js | 4 +- client/assets/js/services/QueryService.js | 3 ++ 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/client/assets/components/documentList/documentList.html b/client/assets/components/documentList/documentList.html index a0d2f227..596dfd67 100644 --- a/client/assets/components/documentList/documentList.html +++ b/client/assets/components/documentList/documentList.html @@ -1,8 +1,10 @@
- Related Items + - click here to launch! + + click to find! + click here to launch! diff --git a/client/assets/components/documentList/documentList.js b/client/assets/components/documentList/documentList.js index c44a4979..f2b5ecd3 100644 --- a/client/assets/components/documentList/documentList.js +++ b/client/assets/components/documentList/documentList.js @@ -31,8 +31,8 @@ vm.toggleGroupedResults = toggleGroupedResults; vm.showGroupedResults = {}; vm.getDocPosition = getDocPosition; - vm.getRelatedItems = getRelatedItems; - vm.launchMlt = launchMlt; + vm.getMoreLikeThisFromObservable = getMoreLikeThisFromObservable; + vm.getMoreLikeThisByLaunchingQuery = getMoreLikeThisByLaunchingQuery; @@ -147,21 +147,24 @@ return _.findIndex(docs, doc); } - function getRelatedItems(doc) { - // There are two ways of doing this, the first is by getting the MLT results and checking against the - // document name using the general MLT stage (this is slower because it loads mlt for every document thus - // slowing the inital search. - console.log("Find related items here by querying solr correctly!"); - var resultsObservable = Orwell.getObservable('queryResults'); + /** + * Get the moreLikethis recommendations from a query pipeline in Fusion. This particular method gets the results from + * an observable that gets populated on page load. + * @param {object} doc Doc of which the id is required to return the appropriate mlt results + * @return {list} moreLikeThisForDoc List of "more like this" responses to the document in question + */ + function getMoreLikeThisFromObservable(doc) { + var mltResultsObservable = Orwell.getObservable('mltResults'); + console.log("mltResultsObservable is populated with ", mltResultsObservable) + console.log("The doc is", doc); var docs; - var finalList = []; + var moreLikeThisForDoc = []; - if (resultsObservable.content.moreLikeThis != null) { - console.log("Inside the getRelatedItems!"); - console.log(resultsObservable.content.moreLikeThis); - for (var item in resultsObservable.content.moreLikeThis) { + if (mltResultsObservable != null) { + console.log("We have More Like This Results, Lets Find the Right One"); + for (var item in mltResultsObservable.content) { if (item == doc.id) { - docs = resultsObservable.content.moreLikeThis[item].docs; + docs = mltResultsObservable[item].docs; break; } } @@ -172,28 +175,29 @@ } else { for (var doc in docs){ - finalList.push(docs[doc].title); + moreLikeThisForDoc.push(docs[doc].title); } } - return finalList; } + return moreLikeThisForDoc; } - function launchMlt(doc) { - console.log("launching mlt"); - console.log(doc.id); - vm.id = doc.id + /** + * Get moreLikeThis recommendations from a query pipeline in fusion. This particular method gets the + * results by launching the mlt search for the particular doc in question and returning the results. + * @param {object} doc Doc of which the id is required to launch the appropriate query + * @return {list} mltResults List of "more Like This" responses to the document in question + */ + function getMoreLikeThisByLaunchingQuery(doc) { + console.log("launching query based on doc ", vm.id); + vm.id = doc.id; QueryDataService.getMltQueryResults({q: "id:" + vm.id, wt: 'json'}).then(manipulate_mlt); function manipulate_mlt(response){ - console.log("Done getting the stuff"); - console.log(vm.id); var mltResults = Orwell.getObservable('mltResults').content[vm.id].docs; return mltResults; } - } - } })(); diff --git a/client/assets/js/services/ConfigService.js b/client/assets/js/services/ConfigService.js index 8f2e7093..adf86f3f 100644 --- a/client/assets/js/services/ConfigService.js +++ b/client/assets/js/services/ConfigService.js @@ -79,7 +79,6 @@ getQueryProfile: getQueryProfile, getCollectionName: getCollectionName, getQueryPipeline: getQueryPipeline, - getMltPipeline: getMltPipeline, getLoginCredentials: getLoginCredentials, getIfQueryProfile: getIfQueryProfile, getFieldLabels: getFieldLabels, diff --git a/client/assets/js/services/QueryDataService.js b/client/assets/js/services/QueryDataService.js index fb5c8f2f..e67157bf 100644 --- a/client/assets/js/services/QueryDataService.js +++ b/client/assets/js/services/QueryDataService.js @@ -56,7 +56,6 @@ .catch(failure); function success(response) { - console.log("Success!!!! getting response"); console.log(response); // Set the content to populate the rest of the ui. queryResultsObservable.setContent(response.data); @@ -80,7 +79,7 @@ var queryString = QueryBuilder.objectToURLString(query); var fullUrl = getMltQueryUrl() + '?' + queryString; - console.log('urllll', fullUrl); + console.log("Full MLT Query URL Is as Follows", fullUrl); $http .get(fullUrl) @@ -88,7 +87,6 @@ .catch(failure); function success(response) { - console.log('responseeee', response.data.moreLikeThis); mltResultsObservable.setContent(response.data.moreLikeThis); deferred.resolve(response.data.moreLikeThis); } diff --git a/client/assets/js/services/QueryService.js b/client/assets/js/services/QueryService.js index 8463c77f..d3ee250a 100644 --- a/client/assets/js/services/QueryService.js +++ b/client/assets/js/services/QueryService.js @@ -31,7 +31,10 @@ queryObservable.addObserver(function (query) { QueryDataService.getQueryResults(query); + }); + queryObservable.addObserver(function (query) { + QueryDataService.getMltQueryResults(query); }); return { From e5f8d40eb222fac4a3e2e125f4ccb1783b176755 Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Tue, 6 Sep 2016 11:26:51 -0700 Subject: [PATCH 05/16] added better visualization for the recommenders in view --- .../documentList/_documentList.scss | 20 +++++ .../components/documentList/documentList.html | 12 ++- .../components/documentList/documentList.js | 88 ++++++++++++++++--- client/assets/js/services/ConfigService.js | 1 + client/assets/js/services/QueryDataService.js | 43 ++++++--- client/assets/js/services/QueryService.js | 2 +- 6 files changed, 140 insertions(+), 26 deletions(-) diff --git a/client/assets/components/documentList/_documentList.scss b/client/assets/components/documentList/_documentList.scss index bf6cb6ee..2cb303b5 100644 --- a/client/assets/components/documentList/_documentList.scss +++ b/client/assets/components/documentList/_documentList.scss @@ -1,3 +1,23 @@ #documentList{ em{ background-color:$highlight-color;} } + +#overlay { + visibility: hidden; + position: absolute; + left: 0px; + top: 0px; + width:100%; + height:100%; + text-align:left; + z-index: 1000; +} + +#overlay pre { + width:70%; + margin: 100px auto; + background-color: #fff; + border:1px solid #000; + padding:15px; + text-align:left; +} diff --git a/client/assets/components/documentList/documentList.html b/client/assets/components/documentList/documentList.html index 596dfd67..386d36d6 100644 --- a/client/assets/components/documentList/documentList.html +++ b/client/assets/components/documentList/documentList.html @@ -3,9 +3,15 @@ - click to find! - click here to launch! - + click to find! + + Click Here to Find More Like This Document + +
+
+      
+
+ diff --git a/client/assets/components/documentList/documentList.js b/client/assets/components/documentList/documentList.js index f2b5ecd3..fe4ada06 100644 --- a/client/assets/components/documentList/documentList.js +++ b/client/assets/components/documentList/documentList.js @@ -33,13 +33,18 @@ vm.getDocPosition = getDocPosition; vm.getMoreLikeThisFromObservable = getMoreLikeThisFromObservable; vm.getMoreLikeThisByLaunchingQuery = getMoreLikeThisByLaunchingQuery; - - + vm.getMoreLikeThisByLaunchingQueryAgainstPipeline = getMoreLikeThisByLaunchingQueryAgainstPipeline; + vm.overlay = overlay; activate(); //////// + function overlay() { + var el = document.getElementById("overlay"); + el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible"; + } + function activate() { var resultsObservable = Orwell.getObservable('queryResults'); resultsObservable.addObserver(function (data) { @@ -155,13 +160,14 @@ */ function getMoreLikeThisFromObservable(doc) { var mltResultsObservable = Orwell.getObservable('mltResults'); - console.log("mltResultsObservable is populated with ", mltResultsObservable) - console.log("The doc is", doc); var docs; - var moreLikeThisForDoc = []; + var moreLikeThisForDoc = []; - if (mltResultsObservable != null) { - console.log("We have More Like This Results, Lets Find the Right One"); + if (mltResultsObservable.content == null || mltResultsObservable.content == undefined) { + return moreLikeThisForDoc; + } + + else if (mltResultsObservable.content != null) { for (var item in mltResultsObservable.content) { if (item == doc.id) { docs = mltResultsObservable[item].docs; @@ -183,21 +189,79 @@ } /** - * Get moreLikeThis recommendations from a query pipeline in fusion. This particular method gets the + * Get moreLikeThis recommendations from a direct query to fusion specifying the document + * id and necessary mlt. This particular method gets the * results by launching the mlt search for the particular doc in question and returning the results. * @param {object} doc Doc of which the id is required to launch the appropriate query * @return {list} mltResults List of "more Like This" responses to the document in question */ function getMoreLikeThisByLaunchingQuery(doc) { + vm.overlay(); console.log("launching query based on doc ", vm.id); vm.id = doc.id; - - QueryDataService.getMltQueryResults({q: "id:" + vm.id, wt: 'json'}).then(manipulate_mlt); + QueryDataService.getMoreLikeThisForOneDoc({q: "{!mlt qf=body}" + vm.id, wt:'json'}).then(manipulate_mlt); function manipulate_mlt(response){ - var mltResults = Orwell.getObservable('mltResults').content[vm.id].docs; - return mltResults; + var rawMoreLikeThisResults = Orwell.getObservable('mltResults').content.response.docs; + var parsedMoreLikeThisResults = "" + + for (var resultIndex in rawMoreLikeThisResults) { + var moreLikeThisToParse = rawMoreLikeThisResults[resultIndex]; + var index = parseInt(resultIndex) + 1 + if (moreLikeThisToParse.title != null) { + parsedMoreLikeThisResults += index.toString() + ": " + moreLikeThisToParse.title + "\n"; + } + else{ + parsedMoreLikeThisResults += moreLikeThisToParse.id + "\n"; + } + } + + console.log("The Results Are as follows", parsedMoreLikeThisResults); + document.getElementById('MoreLikeThisByDocIdResults').innerHTML = parsedMoreLikeThisResults; + return parsedMoreLikeThisResults; } } + + function loadJSON(path, success, error) { + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState === XMLHttpRequest.DONE){ + if (xhr.status === 200) { + if (success) + success(JSON.parse(xhr.responseText)); + } else { + if (error) + error(xhr); + } + } + }; + xhr.open("GET", path, true); + xhr.send(); + } + /** + * Get moreLikeThis recommendations from a query pipeline in fusion. This particular method gets the + * results by launching the mlt search for the particular doc in question and returning the results. + * @param {object} doc Doc of which the id is required to launch the appropriate query + * @return {list} mltResults List of "more Like This" responses to the document in question + */ + function getMoreLikeThisByLaunchingQueryAgainstPipeline(doc){ + // loadJSON('api/apollo/query-pipelines/default_mlt/', function(data) {console.log(data); }, function(xhr) {console.error(xhr)}); + + // var newName = 'John Smith'; + // var xhr = new XMLHttpRequest(); + // xhr.open('POST', 'api/apollo/query-pipelines/default_mlt'); + // xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + // xhr.onload = function() { + // if (xhr.status === 200 && xhr.responseText !== newName){ + // alert('Something went wrong! Nemw is now' + xhr.responseText); + // } + // else if (xhr.status !== 200) { + // alert ("Request failed. Returned wrong status"); + // } + // }; + // xhr.send(encodeURI('name=' + newName)); + + + } } })(); diff --git a/client/assets/js/services/ConfigService.js b/client/assets/js/services/ConfigService.js index adf86f3f..473a847c 100644 --- a/client/assets/js/services/ConfigService.js +++ b/client/assets/js/services/ConfigService.js @@ -77,6 +77,7 @@ config: appConfig, getFusionUrl: getFusionUrl, getQueryProfile: getQueryProfile, + getMltPipeline: getMltPipeline, getCollectionName: getCollectionName, getQueryPipeline: getQueryPipeline, getLoginCredentials: getLoginCredentials, diff --git a/client/assets/js/services/QueryDataService.js b/client/assets/js/services/QueryDataService.js index e67157bf..6bf62a7f 100644 --- a/client/assets/js/services/QueryDataService.js +++ b/client/assets/js/services/QueryDataService.js @@ -13,7 +13,7 @@ function Config(OrwellProvider) { 'ngInject'; OrwellProvider.createObservable('queryResults', {}); - OrwellProvider.createObservable('mltResults', {poop:"poop"}); + OrwellProvider.createObservable('mltResults', {}); } function QueryDataService() { @@ -30,8 +30,8 @@ getQueryResults: getQueryResults, getProfileEndpoint: getProfileEndpoint, getPipelineEndpoint: getPipelineEndpoint, - getMltQueryResults: getMltQueryResults, - getMltQueryUrl: getMltQueryUrl + getMoreLikeThisForAllDocs: getMoreLikeThisForAllDocs, + getMoreLikeThisForOneDoc: getMoreLikeThisForOneDoc, }; /** @@ -45,11 +45,8 @@ var deferred = $q.defer(); var queryString = QueryBuilder.objectToURLString(query); - - console.log("In getqueryresults and trying to access mlt pipeline"); var fullUrl = getQueryUrl(ConfigService.getIfQueryProfile()) + '?' + queryString; - console.log(fullUrl); - + $http .get(fullUrl) .then(success) @@ -72,13 +69,12 @@ return deferred.promise; } - - function getMltQueryResults(query, id) { + function getMoreLikeThisForAllDocs(query, id) { var deferred = $q.defer(); var queryString = QueryBuilder.objectToURLString(query); - var fullUrl = getMltQueryUrl() + '?' + queryString; + var fullUrl = getQueryUrl(ConfigService.getIfQueryProfile()) + '?' + queryString; console.log("Full MLT Query URL Is as Follows", fullUrl); $http @@ -100,6 +96,33 @@ return deferred.promise; } + function getMoreLikeThisForOneDoc(query, id) { + var deferred = $q.defer(); + + var queryString = QueryBuilder.objectToURLString(query); + + var fullUrl = getQueryUrl(ConfigService.getIfQueryProfile()) + '?' + queryString; + console.log("Full MLT Query URL Is as Follows", fullUrl); + + $http + .get(fullUrl) + .then(success) + .catch(failure); + + function success(response) { + mltResultsObservable.setContent(response.data); + deferred.resolve(response.data); + } + + function failure(err) { + mltResultsObservable.setContent({ + numFound: 0 + }); + deferred.reject(err.data); + } + return deferred.promise; + } + /** * Returns the appropriate base url for an endpoint * diff --git a/client/assets/js/services/QueryService.js b/client/assets/js/services/QueryService.js index d3ee250a..253c1e97 100644 --- a/client/assets/js/services/QueryService.js +++ b/client/assets/js/services/QueryService.js @@ -34,7 +34,7 @@ }); queryObservable.addObserver(function (query) { - QueryDataService.getMltQueryResults(query); + QueryDataService.getMoreLikeThisForAllDocs(query); }); return { From d4bb97222a86b1ee8d48875040b4213e9f638c46 Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Tue, 6 Sep 2016 14:11:40 -0700 Subject: [PATCH 06/16] Added functionality to change the query stage and use that instead of querying directly. Currently both work and are taking the same amount of time. I guess the query stage is more configurable in theory but the way it is written right now it is clobbering all the defaults so I am not sure if that is the best way to go. Will see if there is a way to only change the defaults that are necessary --- .../components/documentList/documentList.html | 16 ++- .../components/documentList/documentList.js | 106 ++++++++++++++---- client/assets/js/services/QueryDataService.js | 25 +++-- 3 files changed, 109 insertions(+), 38 deletions(-) diff --git a/client/assets/components/documentList/documentList.html b/client/assets/components/documentList/documentList.html index 386d36d6..df06eed9 100644 --- a/client/assets/components/documentList/documentList.html +++ b/client/assets/components/documentList/documentList.html @@ -1,12 +1,18 @@
- - - - click to find! + + - Click Here to Find More Like This Document + Click Here to Change the Query Pipeline +
+
+      
+
+ + Click Here to Find More Like This Document
       
diff --git a/client/assets/components/documentList/documentList.js b/client/assets/components/documentList/documentList.js index fe4ada06..062e8240 100644 --- a/client/assets/components/documentList/documentList.js +++ b/client/assets/components/documentList/documentList.js @@ -159,18 +159,20 @@ * @return {list} moreLikeThisForDoc List of "more like this" responses to the document in question */ function getMoreLikeThisFromObservable(doc) { - var mltResultsObservable = Orwell.getObservable('mltResults'); + var mltResultsObservable2 = Orwell.getObservable('mltResults2'); + console.log(mltResultsObservable2.content); var docs; var moreLikeThisForDoc = []; - if (mltResultsObservable.content == null || mltResultsObservable.content == undefined) { + if (mltResultsObservable2.content == null || mltResultsObservable2.content == undefined) { + console.log("We have no more like This"); return moreLikeThisForDoc; } - else if (mltResultsObservable.content != null) { - for (var item in mltResultsObservable.content) { + else if (mltResultsObservable2.content != null) { + for (var item in mltResultsObservable2.content) { if (item == doc.id) { - docs = mltResultsObservable[item].docs; + docs = mltResultsObservable2[item].docs; break; } } @@ -185,6 +187,7 @@ } } } + console.log(moreLikeThisForDoc); return moreLikeThisForDoc; } @@ -197,7 +200,6 @@ */ function getMoreLikeThisByLaunchingQuery(doc) { vm.overlay(); - console.log("launching query based on doc ", vm.id); vm.id = doc.id; QueryDataService.getMoreLikeThisForOneDoc({q: "{!mlt qf=body}" + vm.id, wt:'json'}).then(manipulate_mlt); @@ -216,12 +218,63 @@ } } - console.log("The Results Are as follows", parsedMoreLikeThisResults); document.getElementById('MoreLikeThisByDocIdResults').innerHTML = parsedMoreLikeThisResults; return parsedMoreLikeThisResults; } } + function putJSON(path, id, success, error) { + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState === XMLHttpRequest.DONE){ + if (xhr.status === 200) { + if (success) + success(JSON.parse(xhr.responseText)); + } else { + if (error) + error(xhr); + } + } + }; + xhr.open('PUT', path); + xhr.setRequestHeader('Content-Type', 'application/json'); + xhr.onload = function() { + if (xhr.status === 200) { + var userInfo = JSON.parse(xhr.responseText); + } + }; + xhr.send(JSON.stringify( + { + "id" : "default_mlt", + "stages" : [ { + "type" : "MoreLikeThis", + "id" : "62186129-876c-4a2e-9a08-7c34504ec7c3", + "MoreLikeThisFields" : [ { + "field" : "body" + } ], + "useQueryParser" : true, + "mindf" : 2, + "maxdf" : 100000, + "docId" : id, + "type" : "MoreLikeThis", + "skip" : false, + "label" : "MoreLikeThis" + }, { + "type" : "solr-query", + "id" : "91817c00-fb19-4348-912a-35be342938fc", + "allowedRequestHandlers" : [ ], + "httpMethod" : "POST", + "allowFederatedSearch" : false, + "type" : "solr-query", + "skip" : false, + "label" : "solr-query" + } ], + "properties" : { } + } + )); + } + + function loadJSON(path, success, error) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { @@ -245,23 +298,32 @@ * @return {list} mltResults List of "more Like This" responses to the document in question */ function getMoreLikeThisByLaunchingQueryAgainstPipeline(doc){ - // loadJSON('api/apollo/query-pipelines/default_mlt/', function(data) {console.log(data); }, function(xhr) {console.error(xhr)}); + vm.overlay(); + putJSON('/api/apollo/query-pipelines/default_mlt/', doc.id, function(data) { + console.log(data); + QueryDataService.getMoreLikeThisForAllDocs({wt:'json'}).then(displayResults); + + function displayResults(response){ + var rawMoreLikeThisResults = Orwell.getObservable('mltResults2').content.response.docs; + console.log(rawMoreLikeThisResults); - // var newName = 'John Smith'; - // var xhr = new XMLHttpRequest(); - // xhr.open('POST', 'api/apollo/query-pipelines/default_mlt'); - // xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - // xhr.onload = function() { - // if (xhr.status === 200 && xhr.responseText !== newName){ - // alert('Something went wrong! Nemw is now' + xhr.responseText); - // } - // else if (xhr.status !== 200) { - // alert ("Request failed. Returned wrong status"); - // } - // }; - // xhr.send(encodeURI('name=' + newName)); + var parsedMoreLikeThisResults = "" - + for (var resultIndex in rawMoreLikeThisResults) { + var moreLikeThisToParse = rawMoreLikeThisResults[resultIndex]; + var index = parseInt(resultIndex) + 1 + if (moreLikeThisToParse.title != null) { + parsedMoreLikeThisResults += index.toString() + ": " + moreLikeThisToParse.title + "\n"; + } + else{ + parsedMoreLikeThisResults += moreLikeThisToParse.id + "\n"; + } + } + + document.getElementById('MoreLikeThisOverallResults').innerHTML = parsedMoreLikeThisResults; + return parsedMoreLikeThisResults; + } + }, function(xhr) {console.error(xhr)}); } } })(); diff --git a/client/assets/js/services/QueryDataService.js b/client/assets/js/services/QueryDataService.js index 6bf62a7f..5addbc75 100644 --- a/client/assets/js/services/QueryDataService.js +++ b/client/assets/js/services/QueryDataService.js @@ -14,6 +14,7 @@ 'ngInject'; OrwellProvider.createObservable('queryResults', {}); OrwellProvider.createObservable('mltResults', {}); + OrwellProvider.createObservable('mltResults2', {}); } function QueryDataService() { @@ -26,6 +27,7 @@ 'ngInject'; var queryResultsObservable = Orwell.getObservable('queryResults'); var mltResultsObservable = Orwell.getObservable('mltResults'); + var mltResultsObservable2 = Orwell.getObservable('mltResults2'); return { getQueryResults: getQueryResults, getProfileEndpoint: getProfileEndpoint, @@ -46,7 +48,8 @@ var queryString = QueryBuilder.objectToURLString(query); var fullUrl = getQueryUrl(ConfigService.getIfQueryProfile()) + '?' + queryString; - + console.log("Full Url in the getQueryResults Portion", fullUrl); + $http .get(fullUrl) .then(success) @@ -74,7 +77,7 @@ var queryString = QueryBuilder.objectToURLString(query); - var fullUrl = getQueryUrl(ConfigService.getIfQueryProfile()) + '?' + queryString; + var fullUrl = getMltQueryUrl(ConfigService.getIfQueryProfile()) + '?' + queryString; console.log("Full MLT Query URL Is as Follows", fullUrl); $http @@ -83,12 +86,12 @@ .catch(failure); function success(response) { - mltResultsObservable.setContent(response.data.moreLikeThis); + mltResultsObservable2.setContent(response.data); deferred.resolve(response.data.moreLikeThis); } function failure(err) { - mltResultsObservable.setContent({ + mltResultsObservable2.setContent({ numFound: 0 }); deferred.reject(err.data); @@ -110,12 +113,12 @@ .catch(failure); function success(response) { - mltResultsObservable.setContent(response.data); + mltResultsObservable2.setContent(response.data); deferred.resolve(response.data); } function failure(err) { - mltResultsObservable.setContent({ + mltResultsObservable2.setContent({ numFound: 0 }); deferred.reject(err.data); @@ -136,6 +139,11 @@ return isProfiles ? profilesEndpoint : pipelinesEndpoint; } + function getMltQueryUrl(){ + var pipelinesEndpoint = getPipelineEndpoint(ConfigService.getMltPipeline(), 'select'); + return pipelinesEndpoint; + } + function getProfileEndpoint(profile, requestHandler){ return ApiBase.getEndpoint() + 'api/apollo/collections/' + ConfigService.getCollectionName() + '/query-profiles/' + @@ -148,11 +156,6 @@ '/' + requestHandler; } - function getMltQueryUrl(){ - var pipelinesEndpoint = getPipelineEndpoint(ConfigService.getMltPipeline(), 'select'); - return pipelinesEndpoint; - } - } } })(); From 6ef762bc6481f2b159443c1781a9ca8ed3db4d3c Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Tue, 6 Sep 2016 15:18:19 -0700 Subject: [PATCH 07/16] Cleaned up code slightly, still have to add comments and get the overall observable working. Two methods are still implemented right now. Still need to make sure all configs are coming from the config file --- .../documentList/_documentList.scss | 20 ++ .../components/documentList/documentList.html | 6 +- .../components/documentList/documentList.js | 180 ++++++++---------- client/assets/js/services/QueryDataService.js | 25 ++- client/assets/js/services/QueryService.js | 4 - 5 files changed, 115 insertions(+), 120 deletions(-) diff --git a/client/assets/components/documentList/_documentList.scss b/client/assets/components/documentList/_documentList.scss index 2cb303b5..ddaf68f0 100644 --- a/client/assets/components/documentList/_documentList.scss +++ b/client/assets/components/documentList/_documentList.scss @@ -21,3 +21,23 @@ padding:15px; text-align:left; } + +#overlay_second { + visibility: hidden; + position: absolute; + left: 0px; + top: 0px; + width:100%; + height:100%; + text-align:left; + z-index: 1000; +} + +#overlay_second div { + width:70%; + margin: 100px auto; + background-color: #fff; + border:1px solid #000; + padding:15px; + text-align:left; +} diff --git a/client/assets/components/documentList/documentList.html b/client/assets/components/documentList/documentList.html index df06eed9..fe625019 100644 --- a/client/assets/components/documentList/documentList.html +++ b/client/assets/components/documentList/documentList.html @@ -6,13 +6,13 @@ Click Here To Find More Like This Document In A Different Way --> - Click Here to Change the Query Pipeline +
Click Here to Change the Query Pipeline
-
+      
       
- Click Here to Find More Like This Document +
Click Here to Find More Like This Document
       
diff --git a/client/assets/components/documentList/documentList.js b/client/assets/components/documentList/documentList.js index 062e8240..e4cd5664 100644 --- a/client/assets/components/documentList/documentList.js +++ b/client/assets/components/documentList/documentList.js @@ -152,76 +152,6 @@ return _.findIndex(docs, doc); } - /** - * Get the moreLikethis recommendations from a query pipeline in Fusion. This particular method gets the results from - * an observable that gets populated on page load. - * @param {object} doc Doc of which the id is required to return the appropriate mlt results - * @return {list} moreLikeThisForDoc List of "more like this" responses to the document in question - */ - function getMoreLikeThisFromObservable(doc) { - var mltResultsObservable2 = Orwell.getObservable('mltResults2'); - console.log(mltResultsObservable2.content); - var docs; - var moreLikeThisForDoc = []; - - if (mltResultsObservable2.content == null || mltResultsObservable2.content == undefined) { - console.log("We have no more like This"); - return moreLikeThisForDoc; - } - - else if (mltResultsObservable2.content != null) { - for (var item in mltResultsObservable2.content) { - if (item == doc.id) { - docs = mltResultsObservable2[item].docs; - break; - } - } - } - if (docs != undefined) { - if (docs.length == 0) { - return "No Related Items Found!" - } - else { - for (var doc in docs){ - moreLikeThisForDoc.push(docs[doc].title); - } - } - } - console.log(moreLikeThisForDoc); - return moreLikeThisForDoc; - } - - /** - * Get moreLikeThis recommendations from a direct query to fusion specifying the document - * id and necessary mlt. This particular method gets the - * results by launching the mlt search for the particular doc in question and returning the results. - * @param {object} doc Doc of which the id is required to launch the appropriate query - * @return {list} mltResults List of "more Like This" responses to the document in question - */ - function getMoreLikeThisByLaunchingQuery(doc) { - vm.overlay(); - vm.id = doc.id; - QueryDataService.getMoreLikeThisForOneDoc({q: "{!mlt qf=body}" + vm.id, wt:'json'}).then(manipulate_mlt); - - function manipulate_mlt(response){ - var rawMoreLikeThisResults = Orwell.getObservable('mltResults').content.response.docs; - var parsedMoreLikeThisResults = "" - - for (var resultIndex in rawMoreLikeThisResults) { - var moreLikeThisToParse = rawMoreLikeThisResults[resultIndex]; - var index = parseInt(resultIndex) + 1 - if (moreLikeThisToParse.title != null) { - parsedMoreLikeThisResults += index.toString() + ": " + moreLikeThisToParse.title + "\n"; - } - else{ - parsedMoreLikeThisResults += moreLikeThisToParse.id + "\n"; - } - } - - document.getElementById('MoreLikeThisByDocIdResults').innerHTML = parsedMoreLikeThisResults; - return parsedMoreLikeThisResults; - } - } function putJSON(path, id, success, error) { var xhr = new XMLHttpRequest(); @@ -274,23 +204,82 @@ )); } + function manipulateResults() { + var rawMoreLikeThisResults = Orwell.getObservable('mltResults').content.response.docs; + // console.log(rawMoreLikeThisResults); + var parsedMoreLikeThisResults = "" - function loadJSON(path, success, error) { - var xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function() { - if (xhr.readyState === XMLHttpRequest.DONE){ - if (xhr.status === 200) { - if (success) - success(JSON.parse(xhr.responseText)); - } else { - if (error) - error(xhr); + for (var resultIndex in rawMoreLikeThisResults) { + var moreLikeThisToParse = rawMoreLikeThisResults[resultIndex]; + var index = parseInt(resultIndex) + 1 + if (moreLikeThisToParse.title != null) { + parsedMoreLikeThisResults += index.toString() + ": " + moreLikeThisToParse.title + "\n"; + } + else{ + parsedMoreLikeThisResults += moreLikeThisToParse.id + "\n"; + } + } + // console.log(parsedMoreLikeThisResults); + return parsedMoreLikeThisResults; + } + + /** + * Get the moreLikethis recommendations from a query pipeline in Fusion. This particular method gets the results from + * an observable that gets populated on page load. + * @param {object} doc Doc of which the id is required to return the appropriate mlt results + * @return {list} moreLikeThisForDoc List of "more like this" responses to the document in question + */ + function getMoreLikeThisFromObservable(doc) { + var mltResultsObservable = Orwell.getObservable('mltResults'); + console.log(mltResultsObservable.content); + var docs; + var moreLikeThisForDoc = []; + + if (mltResultsObservable.content == null || mltResultsObservable.content == undefined) { + console.log("We have no more like This"); + return moreLikeThisForDoc; + } + + else if (mltResultsObservable.content != null) { + for (var item in mltResultsObservable.content) { + if (item == doc.id) { + docs = mltResultsObservable[item].docs; + break; } } - }; - xhr.open("GET", path, true); - xhr.send(); + } + if (docs != undefined) { + if (docs.length == 0) { + return "No Related Items Found!" + } + else { + for (var doc in docs){ + moreLikeThisForDoc.push(docs[doc].title); + } + } + } + console.log(moreLikeThisForDoc); + return moreLikeThisForDoc; } + + /** + * Get moreLikeThis recommendations from a direct query to fusion specifying the document + * id and necessary mlt. This particular method gets the + * results by launching the mlt search for the particular doc in question and returning the results. + * @param {object} doc Doc of which the id is required to launch the appropriate query + * @return {list} mltResults List of "more Like This" responses to the document in question + */ + function getMoreLikeThisByLaunchingQuery(doc) { + vm.overlay(); + QueryDataService.getMoreLikeThisResults({q: "{!mlt qf=body}".concat(doc.id.toString()), wt:'json'}, false).then(displayResults); + + function displayResults(response){ + var parsedMoreLikeThisResults = manipulateResults(); + // console.log(parsedMoreLikeThisResults); + document.getElementById('MoreLikeThisByDocIdResults').innerHTML = parsedMoreLikeThisResults; + } + } + /** * Get moreLikeThis recommendations from a query pipeline in fusion. This particular method gets the * results by launching the mlt search for the particular doc in question and returning the results. @@ -300,29 +289,14 @@ function getMoreLikeThisByLaunchingQueryAgainstPipeline(doc){ vm.overlay(); putJSON('/api/apollo/query-pipelines/default_mlt/', doc.id, function(data) { - console.log(data); - QueryDataService.getMoreLikeThisForAllDocs({wt:'json'}).then(displayResults); + // console.log(data); + QueryDataService.getMoreLikeThisResults({wt:'json'}, true).then(displayResults); function displayResults(response){ - var rawMoreLikeThisResults = Orwell.getObservable('mltResults2').content.response.docs; - console.log(rawMoreLikeThisResults); - - var parsedMoreLikeThisResults = "" - - for (var resultIndex in rawMoreLikeThisResults) { - var moreLikeThisToParse = rawMoreLikeThisResults[resultIndex]; - var index = parseInt(resultIndex) + 1 - if (moreLikeThisToParse.title != null) { - parsedMoreLikeThisResults += index.toString() + ": " + moreLikeThisToParse.title + "\n"; - } - else{ - parsedMoreLikeThisResults += moreLikeThisToParse.id + "\n"; - } + var parsedMoreLikeThisResults = manipulateResults(); + // console.log(parsedMoreLikeThisResults); + document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = parsedMoreLikeThisResults; } - - document.getElementById('MoreLikeThisOverallResults').innerHTML = parsedMoreLikeThisResults; - return parsedMoreLikeThisResults; - } }, function(xhr) {console.error(xhr)}); } } diff --git a/client/assets/js/services/QueryDataService.js b/client/assets/js/services/QueryDataService.js index 5addbc75..c4457692 100644 --- a/client/assets/js/services/QueryDataService.js +++ b/client/assets/js/services/QueryDataService.js @@ -27,12 +27,11 @@ 'ngInject'; var queryResultsObservable = Orwell.getObservable('queryResults'); var mltResultsObservable = Orwell.getObservable('mltResults'); - var mltResultsObservable2 = Orwell.getObservable('mltResults2'); return { getQueryResults: getQueryResults, getProfileEndpoint: getProfileEndpoint, getPipelineEndpoint: getPipelineEndpoint, - getMoreLikeThisForAllDocs: getMoreLikeThisForAllDocs, + getMoreLikeThisResults: getMoreLikeThisResults, getMoreLikeThisForOneDoc: getMoreLikeThisForOneDoc, }; @@ -72,12 +71,18 @@ return deferred.promise; } - function getMoreLikeThisForAllDocs(query, id) { + function getMoreLikeThisResults(query, pipeline) { var deferred = $q.defer(); var queryString = QueryBuilder.objectToURLString(query); - - var fullUrl = getMltQueryUrl(ConfigService.getIfQueryProfile()) + '?' + queryString; + var fullUrl; + if (pipeline == true) { + fullUrl = getMltQueryUrl(ConfigService.getIfQueryProfile()) + '?' + queryString; + } + else { + console.log("We are doing this individually!"); + fullUrl = getQueryUrl(ConfigService.getIfQueryProfile()) + '?' + queryString; + } console.log("Full MLT Query URL Is as Follows", fullUrl); $http @@ -86,12 +91,12 @@ .catch(failure); function success(response) { - mltResultsObservable2.setContent(response.data); - deferred.resolve(response.data.moreLikeThis); + mltResultsObservable.setContent(response.data); + deferred.resolve(response.data); } function failure(err) { - mltResultsObservable2.setContent({ + mltResultsObservable.setContent({ numFound: 0 }); deferred.reject(err.data); @@ -113,12 +118,12 @@ .catch(failure); function success(response) { - mltResultsObservable2.setContent(response.data); + mltResultsObservable.setContent(response.data); deferred.resolve(response.data); } function failure(err) { - mltResultsObservable2.setContent({ + mltResultsObservable.setContent({ numFound: 0 }); deferred.reject(err.data); diff --git a/client/assets/js/services/QueryService.js b/client/assets/js/services/QueryService.js index 253c1e97..4e658bb8 100644 --- a/client/assets/js/services/QueryService.js +++ b/client/assets/js/services/QueryService.js @@ -33,10 +33,6 @@ QueryDataService.getQueryResults(query); }); - queryObservable.addObserver(function (query) { - QueryDataService.getMoreLikeThisForAllDocs(query); - }); - return { setQuery: setQuery, getQueryObservable: getQueryObservable, From bfd751b49198a007bf34292bd0799a929c1c56dc Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Tue, 6 Sep 2016 15:39:58 -0700 Subject: [PATCH 08/16] added comments and cleaned code further, made the pipeline and fields configurable --- .../components/documentList/documentList.js | 17 +++++-- client/assets/js/services/ConfigService.js | 9 +++- client/assets/js/services/QueryDataService.js | 48 +++++++------------ 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/client/assets/components/documentList/documentList.js b/client/assets/components/documentList/documentList.js index e4cd5664..61ae6c8b 100644 --- a/client/assets/components/documentList/documentList.js +++ b/client/assets/components/documentList/documentList.js @@ -21,7 +21,7 @@ } - function Controller($sce, $log, $anchorScroll, Orwell, QueryDataService) { + function Controller($sce, $log, $anchorScroll, Orwell, QueryDataService, ConfigService) { 'ngInject'; var vm = this; vm.docs = []; @@ -152,7 +152,12 @@ return _.findIndex(docs, doc); } - + /** + * @param String path local filepath you want to change + * @param String id id you wish to query on + * @param {object} success function you want to execute upon success of PUT + * @param {object} failure function you want to execute upon failut + */ function putJSON(path, id, success, error) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { @@ -175,12 +180,12 @@ }; xhr.send(JSON.stringify( { - "id" : "default_mlt", + "id" : ConfigService.getRecommenderPipeline(), "stages" : [ { "type" : "MoreLikeThis", "id" : "62186129-876c-4a2e-9a08-7c34504ec7c3", "MoreLikeThisFields" : [ { - "field" : "body" + "field" : ConfigService.getRecommenderField(), } ], "useQueryParser" : true, "mindf" : 2, @@ -204,6 +209,10 @@ )); } + /* + * Manipulates the mlt results to make them more readable in the css + * @returns String parsedMoreLikeThisResults String to supply the html + */ function manipulateResults() { var rawMoreLikeThisResults = Orwell.getObservable('mltResults').content.response.docs; // console.log(rawMoreLikeThisResults); diff --git a/client/assets/js/services/ConfigService.js b/client/assets/js/services/ConfigService.js index 473a847c..560f95c7 100644 --- a/client/assets/js/services/ConfigService.js +++ b/client/assets/js/services/ConfigService.js @@ -77,7 +77,8 @@ config: appConfig, getFusionUrl: getFusionUrl, getQueryProfile: getQueryProfile, - getMltPipeline: getMltPipeline, + getRecommenderPipeline: getRecommenderPipeline, + getRecommenderField: getRecommenderField, getCollectionName: getCollectionName, getQueryPipeline: getQueryPipeline, getLoginCredentials: getLoginCredentials, @@ -124,10 +125,14 @@ return appConfig.query_pipeline_id; } - function getMltPipeline() { + function getRecommenderPipeline() { return appConfig.recommender_pipeline_id; } + function getRecommenderField(){ + return appConfig.recommender_field; + } + function getQueryProfile() { return appConfig.query_profile_id; } diff --git a/client/assets/js/services/QueryDataService.js b/client/assets/js/services/QueryDataService.js index c4457692..95d97e7a 100644 --- a/client/assets/js/services/QueryDataService.js +++ b/client/assets/js/services/QueryDataService.js @@ -31,8 +31,7 @@ getQueryResults: getQueryResults, getProfileEndpoint: getProfileEndpoint, getPipelineEndpoint: getPipelineEndpoint, - getMoreLikeThisResults: getMoreLikeThisResults, - getMoreLikeThisForOneDoc: getMoreLikeThisForOneDoc, + getMoreLikeThisResults: getMoreLikeThisResults }; /** @@ -71,6 +70,15 @@ return deferred.promise; } + /** + * Make a query to the query profiles endpoint + * @param {object} query Should have all the query params, like + * For select?q=query&fq=blah you need to pass in an object + * {'q': 'query', 'fq': 'blah'} + * @param {boolean} object Boolean specifying whether to use the default mlt query pipeline + * or not. + * @return {Promise} Promise that resolve with a Fusion response coming from Solr + */ function getMoreLikeThisResults(query, pipeline) { var deferred = $q.defer(); @@ -104,33 +112,6 @@ return deferred.promise; } - function getMoreLikeThisForOneDoc(query, id) { - var deferred = $q.defer(); - - var queryString = QueryBuilder.objectToURLString(query); - - var fullUrl = getQueryUrl(ConfigService.getIfQueryProfile()) + '?' + queryString; - console.log("Full MLT Query URL Is as Follows", fullUrl); - - $http - .get(fullUrl) - .then(success) - .catch(failure); - - function success(response) { - mltResultsObservable.setContent(response.data); - deferred.resolve(response.data); - } - - function failure(err) { - mltResultsObservable.setContent({ - numFound: 0 - }); - deferred.reject(err.data); - } - return deferred.promise; - } - /** * Returns the appropriate base url for an endpoint * @@ -144,8 +125,15 @@ return isProfiles ? profilesEndpoint : pipelinesEndpoint; } + /** + * Returns the appropriate base url for a more like this endpoint, namely the one + * containing the default_mlt pipeline + * + * @param {Boolean} isProfiles Determines which endpoint type to return; + * @return {string} The URL endpoint for the query without parameters. + */ function getMltQueryUrl(){ - var pipelinesEndpoint = getPipelineEndpoint(ConfigService.getMltPipeline(), 'select'); + var pipelinesEndpoint = getPipelineEndpoint(ConfigService.getRecommenderPipeline(), 'select'); return pipelinesEndpoint; } From 6656f7621e7bae806398bb8f8c5469e1f8d1f11d Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Wed, 7 Sep 2016 17:58:12 -0700 Subject: [PATCH 09/16] implemented the query that works with the alternate morelikethis query parser from id without having to change the backend at all --- .../components/documentList/documentList.html | 4 +-- .../components/documentList/documentList.js | 30 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/client/assets/components/documentList/documentList.html b/client/assets/components/documentList/documentList.html index fe625019..d501c889 100644 --- a/client/assets/components/documentList/documentList.html +++ b/client/assets/components/documentList/documentList.html @@ -12,11 +12,11 @@
-
Click Here to Find More Like This Document
+ diff --git a/client/assets/components/documentList/documentList.js b/client/assets/components/documentList/documentList.js index 61ae6c8b..7ead8103 100644 --- a/client/assets/components/documentList/documentList.js +++ b/client/assets/components/documentList/documentList.js @@ -205,7 +205,7 @@ "label" : "solr-query" } ], "properties" : { } - } + } )); } @@ -297,16 +297,26 @@ */ function getMoreLikeThisByLaunchingQueryAgainstPipeline(doc){ vm.overlay(); - putJSON('/api/apollo/query-pipelines/default_mlt/', doc.id, function(data) { - // console.log(data); - QueryDataService.getMoreLikeThisResults({wt:'json'}, true).then(displayResults); + console.log("The Id is", doc.id); + + QueryDataService.getMoreLikeThisResults({q:"id=" + doc.id, wt:'json'}, true).then(displayResults); - function displayResults(response){ - var parsedMoreLikeThisResults = manipulateResults(); - // console.log(parsedMoreLikeThisResults); - document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = parsedMoreLikeThisResults; - } - }, function(xhr) {console.error(xhr)}); + function displayResults(response){ + var parsedMoreLikeThisResults = manipulateResults(); + // console.log(parsedMoreLikeThisResults); + document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = parsedMoreLikeThisResults; + } + + // putJSON('/api/apollo/query-pipelines/default_mlt/', doc.id, function(data) { + // // console.log(data); + // QueryDataService.getMoreLikeThisResults({wt:'json'}, true).then(displayResults); + + // function displayResults(response){ + // var parsedMoreLikeThisResults = manipulateResults(); + // // console.log(parsedMoreLikeThisResults); + // document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = parsedMoreLikeThisResults; + // } + // }, function(xhr) {console.error(xhr)}); } } })(); From 23510b2b7b5aea92b2b967d8cff0662c5878bc86 Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Thu, 8 Sep 2016 11:00:08 -0700 Subject: [PATCH 10/16] made some modifications to the way the query parser stage is called in view to make things more configurable --- client/assets/components/documentList/documentList.js | 3 ++- client/assets/js/services/ConfigService.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/client/assets/components/documentList/documentList.js b/client/assets/components/documentList/documentList.js index 7ead8103..623698bd 100644 --- a/client/assets/components/documentList/documentList.js +++ b/client/assets/components/documentList/documentList.js @@ -298,8 +298,9 @@ function getMoreLikeThisByLaunchingQueryAgainstPipeline(doc){ vm.overlay(); console.log("The Id is", doc.id); + console.log("The Field we want to Id on is", ConfigService.getRecommenderIdField); - QueryDataService.getMoreLikeThisResults({q:"id=" + doc.id, wt:'json'}, true).then(displayResults); + QueryDataService.getMoreLikeThisResults({q:ConfigService.getRecommenderIdField + doc.id, wt:'json'}, true).then(displayResults); function displayResults(response){ var parsedMoreLikeThisResults = manipulateResults(); diff --git a/client/assets/js/services/ConfigService.js b/client/assets/js/services/ConfigService.js index 560f95c7..d3963523 100644 --- a/client/assets/js/services/ConfigService.js +++ b/client/assets/js/services/ConfigService.js @@ -79,6 +79,7 @@ getQueryProfile: getQueryProfile, getRecommenderPipeline: getRecommenderPipeline, getRecommenderField: getRecommenderField, + getRecommenderIdField: getRecommenderIdField, getCollectionName: getCollectionName, getQueryPipeline: getQueryPipeline, getLoginCredentials: getLoginCredentials, @@ -133,6 +134,10 @@ return appConfig.recommender_field; } + function getRecommenderIdField(){ + return appConfig.recommender_id_field; + } + function getQueryProfile() { return appConfig.query_profile_id; } From cb2a4189166060c63c74a140fa24d9a60f504165 Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Thu, 8 Sep 2016 11:05:55 -0700 Subject: [PATCH 11/16] fixed bug in the view --- client/assets/components/documentList/documentList.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/assets/components/documentList/documentList.js b/client/assets/components/documentList/documentList.js index 623698bd..81950465 100644 --- a/client/assets/components/documentList/documentList.js +++ b/client/assets/components/documentList/documentList.js @@ -298,9 +298,10 @@ function getMoreLikeThisByLaunchingQueryAgainstPipeline(doc){ vm.overlay(); console.log("The Id is", doc.id); - console.log("The Field we want to Id on is", ConfigService.getRecommenderIdField); + var idField = ConfigService.getRecommenderIdField(); + console.log("The Field we want to Id on is", idField); - QueryDataService.getMoreLikeThisResults({q:ConfigService.getRecommenderIdField + doc.id, wt:'json'}, true).then(displayResults); + QueryDataService.getMoreLikeThisResults({q: idField + "=" + doc.id, wt:'json'}, true).then(displayResults); function displayResults(response){ var parsedMoreLikeThisResults = manipulateResults(); From 3290e2eb792245090a3b44b639245e248e4f3b09 Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Thu, 8 Sep 2016 13:32:50 -0700 Subject: [PATCH 12/16] fixed small bug) --- .../components/documentList/documentList.js | 82 +++---------------- 1 file changed, 10 insertions(+), 72 deletions(-) diff --git a/client/assets/components/documentList/documentList.js b/client/assets/components/documentList/documentList.js index 81950465..a6035b6e 100644 --- a/client/assets/components/documentList/documentList.js +++ b/client/assets/components/documentList/documentList.js @@ -152,63 +152,6 @@ return _.findIndex(docs, doc); } - /** - * @param String path local filepath you want to change - * @param String id id you wish to query on - * @param {object} success function you want to execute upon success of PUT - * @param {object} failure function you want to execute upon failut - */ - function putJSON(path, id, success, error) { - var xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function() { - if (xhr.readyState === XMLHttpRequest.DONE){ - if (xhr.status === 200) { - if (success) - success(JSON.parse(xhr.responseText)); - } else { - if (error) - error(xhr); - } - } - }; - xhr.open('PUT', path); - xhr.setRequestHeader('Content-Type', 'application/json'); - xhr.onload = function() { - if (xhr.status === 200) { - var userInfo = JSON.parse(xhr.responseText); - } - }; - xhr.send(JSON.stringify( - { - "id" : ConfigService.getRecommenderPipeline(), - "stages" : [ { - "type" : "MoreLikeThis", - "id" : "62186129-876c-4a2e-9a08-7c34504ec7c3", - "MoreLikeThisFields" : [ { - "field" : ConfigService.getRecommenderField(), - } ], - "useQueryParser" : true, - "mindf" : 2, - "maxdf" : 100000, - "docId" : id, - "type" : "MoreLikeThis", - "skip" : false, - "label" : "MoreLikeThis" - }, { - "type" : "solr-query", - "id" : "91817c00-fb19-4348-912a-35be342938fc", - "allowedRequestHandlers" : [ ], - "httpMethod" : "POST", - "allowFederatedSearch" : false, - "type" : "solr-query", - "skip" : false, - "label" : "solr-query" - } ], - "properties" : { } - } - )); - } - /* * Manipulates the mlt results to make them more readable in the css * @returns String parsedMoreLikeThisResults String to supply the html @@ -299,26 +242,21 @@ vm.overlay(); console.log("The Id is", doc.id); var idField = ConfigService.getRecommenderIdField(); + console.log("The Field we want to Id on is", idField); - - QueryDataService.getMoreLikeThisResults({q: idField + "=" + doc.id, wt:'json'}, true).then(displayResults); + if (idField == null) { + console.log("We don't have an id field!"); + QueryDataService.getMoreLikeThisResults({q: doc.id, wt:'json'}, true).then(displayResults); + } + else { + console.log("We have an id field!"); + QueryDataService.getMoreLikeThisResults({q: idField + "=" + doc.id, wt:'json'}, true).then(displayResults); + } function displayResults(response){ var parsedMoreLikeThisResults = manipulateResults(); - // console.log(parsedMoreLikeThisResults); document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = parsedMoreLikeThisResults; - } - - // putJSON('/api/apollo/query-pipelines/default_mlt/', doc.id, function(data) { - // // console.log(data); - // QueryDataService.getMoreLikeThisResults({wt:'json'}, true).then(displayResults); - - // function displayResults(response){ - // var parsedMoreLikeThisResults = manipulateResults(); - // // console.log(parsedMoreLikeThisResults); - // document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = parsedMoreLikeThisResults; - // } - // }, function(xhr) {console.error(xhr)}); + } } } })(); From 9176e138b7d02e8bd574315a79f43fc2697df4f8 Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Mon, 12 Sep 2016 15:46:54 -0700 Subject: [PATCH 13/16] Fixed errors mentioned in the PR --- FUSION_CONFIG.sample.js | 9 ++++ client/assets/components/components.js | 3 +- .../components/documentList/documentList.html | 13 +---- .../components/documentList/documentList.js | 37 +++++-------- .../facetField/facetFieldDirective.js | 1 - .../recommendations/recommendations.html | 32 ----------- .../recommendations/recommendations.js | 54 ------------------- .../recommendations/recommendations.scss | 4 -- 8 files changed, 23 insertions(+), 130 deletions(-) delete mode 100644 client/assets/components/recommendations/recommendations.html delete mode 100644 client/assets/components/recommendations/recommendations.js delete mode 100644 client/assets/components/recommendations/recommendations.scss diff --git a/FUSION_CONFIG.sample.js b/FUSION_CONFIG.sample.js index 902d5e9e..a213a78b 100644 --- a/FUSION_CONFIG.sample.js +++ b/FUSION_CONFIG.sample.js @@ -63,6 +63,15 @@ appConfig = { //eslint-disable-line query_profile_id: 'default', use_query_profile: true, // Force use of query-profile + // The name of the recommender pipeline you want to use + recommender_pipeline_id: 'default_mlt', + + // The field you want to recommend on + recommender_field: 'body', + + // The Name of the Field you will be using to supply your ids + recommender_id_field: 'id', + // Search UI Title // This title appears in a number of places in the app, including page title. // In the header it is replaced by the logo if one is provided. diff --git a/client/assets/components/components.js b/client/assets/components/components.js index 5d014aee..b27aa890 100644 --- a/client/assets/components/components.js +++ b/client/assets/components/components.js @@ -14,6 +14,5 @@ angular.module('lucidworksView.components', [ 'lucidworksView.components.login', 'lucidworksView.components.paginate', 'lucidworksView.components.searchbox', - 'lucidworksView.components.sort', - 'lucidworksView.components.recommendations' + 'lucidworksView.components.sort' ]); diff --git a/client/assets/components/documentList/documentList.html b/client/assets/components/documentList/documentList.html index d501c889..e1ff7fc2 100644 --- a/client/assets/components/documentList/documentList.html +++ b/client/assets/components/documentList/documentList.html @@ -1,23 +1,12 @@
- - - -
Click Here to Change the Query Pipeline
+
Show Related Items
       
- - diff --git a/client/assets/components/documentList/documentList.js b/client/assets/components/documentList/documentList.js index a6035b6e..2ce951ae 100644 --- a/client/assets/components/documentList/documentList.js +++ b/client/assets/components/documentList/documentList.js @@ -32,8 +32,7 @@ vm.showGroupedResults = {}; vm.getDocPosition = getDocPosition; vm.getMoreLikeThisFromObservable = getMoreLikeThisFromObservable; - vm.getMoreLikeThisByLaunchingQuery = getMoreLikeThisByLaunchingQuery; - vm.getMoreLikeThisByLaunchingQueryAgainstPipeline = getMoreLikeThisByLaunchingQueryAgainstPipeline; + vm.getMoreLikeThis = getMoreLikeThis; vm.overlay = overlay; activate(); @@ -214,31 +213,13 @@ return moreLikeThisForDoc; } - /** - * Get moreLikeThis recommendations from a direct query to fusion specifying the document - * id and necessary mlt. This particular method gets the - * results by launching the mlt search for the particular doc in question and returning the results. - * @param {object} doc Doc of which the id is required to launch the appropriate query - * @return {list} mltResults List of "more Like This" responses to the document in question - */ - function getMoreLikeThisByLaunchingQuery(doc) { - vm.overlay(); - QueryDataService.getMoreLikeThisResults({q: "{!mlt qf=body}".concat(doc.id.toString()), wt:'json'}, false).then(displayResults); - - function displayResults(response){ - var parsedMoreLikeThisResults = manipulateResults(); - // console.log(parsedMoreLikeThisResults); - document.getElementById('MoreLikeThisByDocIdResults').innerHTML = parsedMoreLikeThisResults; - } - } - /** * Get moreLikeThis recommendations from a query pipeline in fusion. This particular method gets the * results by launching the mlt search for the particular doc in question and returning the results. * @param {object} doc Doc of which the id is required to launch the appropriate query * @return {list} mltResults List of "more Like This" responses to the document in question */ - function getMoreLikeThisByLaunchingQueryAgainstPipeline(doc){ + function getMoreLikeThis(doc){ vm.overlay(); console.log("The Id is", doc.id); var idField = ConfigService.getRecommenderIdField(); @@ -246,13 +227,19 @@ console.log("The Field we want to Id on is", idField); if (idField == null) { console.log("We don't have an id field!"); - QueryDataService.getMoreLikeThisResults({q: doc.id, wt:'json'}, true).then(displayResults); + idField = "id"; } else { - console.log("We have an id field!"); - QueryDataService.getMoreLikeThisResults({q: idField + "=" + doc.id, wt:'json'}, true).then(displayResults); + console.log("We have an id field!", idField); } - + + var obj = {}; + obj[idField] = doc.id; + obj['wt'] = 'json'; + + console.log(obj); + QueryDataService.getMoreLikeThisResults(obj, true).then(displayResults); + function displayResults(response){ var parsedMoreLikeThisResults = manipulateResults(); document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = parsedMoreLikeThisResults; diff --git a/client/assets/components/facetField/facetFieldDirective.js b/client/assets/components/facetField/facetFieldDirective.js index 38eb4105..7d20cdeb 100644 --- a/client/assets/components/facetField/facetFieldDirective.js +++ b/client/assets/components/facetField/facetFieldDirective.js @@ -6,7 +6,6 @@ .directive('facetField', facetField); function facetField() { - console.log("In the facetfield constructor"); 'ngInject'; return { restrict: 'EA', diff --git a/client/assets/components/recommendations/recommendations.html b/client/assets/components/recommendations/recommendations.html deleted file mode 100644 index c911d0fd..00000000 --- a/client/assets/components/recommendations/recommendations.html +++ /dev/null @@ -1,32 +0,0 @@ -
-

Recommendations

- -
-

More Like This

-
-
- - -
- -
- -
-
- - -
-
- -
-
-
-
diff --git a/client/assets/components/recommendations/recommendations.js b/client/assets/components/recommendations/recommendations.js deleted file mode 100644 index 3602ab99..00000000 --- a/client/assets/components/recommendations/recommendations.js +++ /dev/null @@ -1,54 +0,0 @@ -(function () { - 'use strict'; - angular - .module('lucidworksView.components.recommendations', [ - 'lucidworksView.services', - 'angucomplete-alt', - 'angular-humanize' - ]) - .directive('recommendations', recommendations); - - function recommendations() { - 'ngInject'; - - return { - restrict: 'EA', - templateUrl: 'assets/components/recommendations/recommendations.html', - controller: Controller, - controllerAs: 'rc', - bindToController: {}, - scope: true, - replace: true - }; - } - - function Controller(Orwell, $log) { - console.log("In the controller for the recommendations js stage"); - 'ngInject'; - var rc = this; //eslint-disable-line - rc.mltDocs = []; - rc.cfDocs = []; - rc.preCFDocs = []; - activate(); - - function activate() { - var resultsObservable = Orwell.getObservable('queryResults'); - resultsObservable.addObserver(function(data) { - // Get the recommendations - checkRecommendations(data); - }); - - function checkRecommendations(data) { - // console.log("In the check recommendations portion of the home controller!"); - if (data.hasOwnProperty('moreLikeThis')){ - console.log("We have more like this! Let's populate the rc"); - for (var key in data.moreLikeThis) { - rc.mltDocs.push(data.moreLikeThis[key].docs); - } - console.log(rc.mltDocs); - } - } - - } - } -})(); diff --git a/client/assets/components/recommendations/recommendations.scss b/client/assets/components/recommendations/recommendations.scss deleted file mode 100644 index b3b05c48..00000000 --- a/client/assets/components/recommendations/recommendations.scss +++ /dev/null @@ -1,4 +0,0 @@ -.recHeader{ - padding-top: 10px; - padding-bottom: 10px; -} \ No newline at end of file From 0ac983ab84d2359a74acfc3bf91eb03cfec55b8e Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Tue, 13 Sep 2016 11:59:27 -0700 Subject: [PATCH 14/16] did some code cleanup and added some error handling --- FUSION_CONFIG.sample.js | 2 +- .../documentList/_documentList.scss | 20 ------ .../components/documentList/documentList.js | 70 ++++++++++++------- .../assets/js/controllers/HomeController.js | 14 ---- client/assets/js/services/QueryDataService.js | 4 -- client/assets/js/services/URLService.js | 1 - client/templates/home.html | 4 +- 7 files changed, 47 insertions(+), 68 deletions(-) diff --git a/FUSION_CONFIG.sample.js b/FUSION_CONFIG.sample.js index a213a78b..2fba54f9 100644 --- a/FUSION_CONFIG.sample.js +++ b/FUSION_CONFIG.sample.js @@ -64,7 +64,7 @@ appConfig = { //eslint-disable-line use_query_profile: true, // Force use of query-profile // The name of the recommender pipeline you want to use - recommender_pipeline_id: 'default_mlt', + recommender_pipeline_id: 'related_items', // The field you want to recommend on recommender_field: 'body', diff --git a/client/assets/components/documentList/_documentList.scss b/client/assets/components/documentList/_documentList.scss index ddaf68f0..2cb303b5 100644 --- a/client/assets/components/documentList/_documentList.scss +++ b/client/assets/components/documentList/_documentList.scss @@ -21,23 +21,3 @@ padding:15px; text-align:left; } - -#overlay_second { - visibility: hidden; - position: absolute; - left: 0px; - top: 0px; - width:100%; - height:100%; - text-align:left; - z-index: 1000; -} - -#overlay_second div { - width:70%; - margin: 100px auto; - background-color: #fff; - border:1px solid #000; - padding:15px; - text-align:left; -} diff --git a/client/assets/components/documentList/documentList.js b/client/assets/components/documentList/documentList.js index 2ce951ae..fee57ec7 100644 --- a/client/assets/components/documentList/documentList.js +++ b/client/assets/components/documentList/documentList.js @@ -156,22 +156,40 @@ * @returns String parsedMoreLikeThisResults String to supply the html */ function manipulateResults() { - var rawMoreLikeThisResults = Orwell.getObservable('mltResults').content.response.docs; - // console.log(rawMoreLikeThisResults); - var parsedMoreLikeThisResults = "" - - for (var resultIndex in rawMoreLikeThisResults) { - var moreLikeThisToParse = rawMoreLikeThisResults[resultIndex]; - var index = parseInt(resultIndex) + 1 - if (moreLikeThisToParse.title != null) { - parsedMoreLikeThisResults += index.toString() + ": " + moreLikeThisToParse.title + "\n"; + var parsedMoreLikeThisResults = ""; + var rawMoreLikeThisResults; + + try { + rawMoreLikeThisResults = Orwell.getObservable('mltResults').content.response.docs; + } + catch (err) { + $log.debug(err); + if (error.name === 'TypeError'){ + return "There was an Error querying Fusion. Check your defaults" ; } - else{ - parsedMoreLikeThisResults += moreLikeThisToParse.id + "\n"; + else { + return "Something went wrong!"; } } - // console.log(parsedMoreLikeThisResults); - return parsedMoreLikeThisResults; + // If there are no results this means something about the parameters was off + if (rawMoreLikeThisResults.length == 0) { + return "There are no Related Items that fit the provided parameters. Try changing some of the parameters in your query pipeline"; + } + + // Otherwise we can go ahead and return what we intended + else { + for (var resultIndex in rawMoreLikeThisResults) { + var moreLikeThisToParse = rawMoreLikeThisResults[resultIndex]; + var index = parseInt(resultIndex) + 1 + if (moreLikeThisToParse.title != null) { + parsedMoreLikeThisResults += index.toString() + ": " + moreLikeThisToParse.title + "\n"; + } + else{ + parsedMoreLikeThisResults += moreLikeThisToParse.id + "\n"; + } + } + return parsedMoreLikeThisResults; + } } /** @@ -182,12 +200,11 @@ */ function getMoreLikeThisFromObservable(doc) { var mltResultsObservable = Orwell.getObservable('mltResults'); - console.log(mltResultsObservable.content); var docs; var moreLikeThisForDoc = []; if (mltResultsObservable.content == null || mltResultsObservable.content == undefined) { - console.log("We have no more like This"); + $log.debug("We have no more like This"); return moreLikeThisForDoc; } @@ -209,7 +226,7 @@ } } } - console.log(moreLikeThisForDoc); + $log.debug(moreLikeThisForDoc); return moreLikeThisForDoc; } @@ -221,27 +238,28 @@ */ function getMoreLikeThis(doc){ vm.overlay(); - console.log("The Id is", doc.id); var idField = ConfigService.getRecommenderIdField(); - - console.log("The Field we want to Id on is", idField); if (idField == null) { - console.log("We don't have an id field!"); + $log.debug("We don't have an id field! Setting it to id"); idField = "id"; } - else { - console.log("We have an id field!", idField); - } - + var obj = {}; obj[idField] = doc.id; obj['wt'] = 'json'; - console.log(obj); - QueryDataService.getMoreLikeThisResults(obj, true).then(displayResults); + // Clear the innerhtml to prevent a split second confusion + document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = ""; + QueryDataService.getMoreLikeThisResults(obj, true).then(displayResults, solrError); + function solrError(response) { + $log.debug(response); + document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = response.details; + } + function displayResults(response){ var parsedMoreLikeThisResults = manipulateResults(); + $log.debug("The results are " + parsedMoreLikeThisResults); document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = parsedMoreLikeThisResults; } } diff --git a/client/assets/js/controllers/HomeController.js b/client/assets/js/controllers/HomeController.js index 33dc29c2..79da403c 100644 --- a/client/assets/js/controllers/HomeController.js +++ b/client/assets/js/controllers/HomeController.js @@ -32,10 +32,6 @@ hc.sorting = {}; hc.grouped = false; - // Recommendations Logic - // hc.hasId = false; - hc.showRecommendations = false; - query = URLService.getQueryFromUrl(); //Setting the query object... also populating the the view model hc.searchQuery = _.get(query,'q','*'); @@ -50,8 +46,6 @@ sorting.switchSort = switchSort; createSortList(); - // Get the recommendations - checkRecommendations(data); }); // Force set the query object to change one digest cycle later @@ -62,14 +56,6 @@ }); } - function checkRecommendations(data) { - // console.log("In the check recommendations portion of the home controller!"); - if (data.hasOwnProperty('moreLikeThis')){ - console.log("We have more like this!! Set the home controller to true"); - hc.showRecommendations = true; - } - } - function checkResultsType(data){ if (data.hasOwnProperty('response')) { hc.numFound = data.response.numFound; diff --git a/client/assets/js/services/QueryDataService.js b/client/assets/js/services/QueryDataService.js index 95d97e7a..503a7358 100644 --- a/client/assets/js/services/QueryDataService.js +++ b/client/assets/js/services/QueryDataService.js @@ -46,7 +46,6 @@ var queryString = QueryBuilder.objectToURLString(query); var fullUrl = getQueryUrl(ConfigService.getIfQueryProfile()) + '?' + queryString; - console.log("Full Url in the getQueryResults Portion", fullUrl); $http .get(fullUrl) @@ -54,7 +53,6 @@ .catch(failure); function success(response) { - console.log(response); // Set the content to populate the rest of the ui. queryResultsObservable.setContent(response.data); deferred.resolve(response.data); @@ -88,10 +86,8 @@ fullUrl = getMltQueryUrl(ConfigService.getIfQueryProfile()) + '?' + queryString; } else { - console.log("We are doing this individually!"); fullUrl = getQueryUrl(ConfigService.getIfQueryProfile()) + '?' + queryString; } - console.log("Full MLT Query URL Is as Follows", fullUrl); $http .get(fullUrl) diff --git a/client/assets/js/services/URLService.js b/client/assets/js/services/URLService.js index bfc71cf8..ff0e3e4c 100644 --- a/client/assets/js/services/URLService.js +++ b/client/assets/js/services/URLService.js @@ -42,7 +42,6 @@ $state.go('home', newStateObject, {notify: false, reloadOnSearch: false}); } - /** * Gets query object from URL */ diff --git a/client/templates/home.html b/client/templates/home.html index 5e3f836e..22efbdc0 100644 --- a/client/templates/home.html +++ b/client/templates/home.html @@ -81,8 +81,8 @@
+ -
-
+
From d23ca93559597f3f7dfb58d35c2b3f37701d7f96 Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Wed, 14 Sep 2016 13:38:14 -0700 Subject: [PATCH 15/16] debugs to errors --- client/assets/components/documentList/documentList.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/assets/components/documentList/documentList.js b/client/assets/components/documentList/documentList.js index fee57ec7..3677f6c6 100644 --- a/client/assets/components/documentList/documentList.js +++ b/client/assets/components/documentList/documentList.js @@ -164,10 +164,12 @@ } catch (err) { $log.debug(err); - if (error.name === 'TypeError'){ + if (err.name === 'TypeError'){ + $log.error(err); return "There was an Error querying Fusion. Check your defaults" ; } else { + $log.error(err); return "Something went wrong!"; } } @@ -253,7 +255,7 @@ QueryDataService.getMoreLikeThisResults(obj, true).then(displayResults, solrError); function solrError(response) { - $log.debug(response); + $log.error(response); document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = response.details; } From 350f849e54b3dda3e4357786e7acf467df680ffd Mon Sep 17 00:00:00 2001 From: Lasya Marla Date: Thu, 15 Sep 2016 14:40:28 -0700 Subject: [PATCH 16/16] fixed up how the view looks to be more natural --- .../documentList/_documentList.scss | 26 +++++-------------- .../components/documentList/documentList.html | 12 ++++++--- .../components/documentList/documentList.js | 11 +++++--- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/client/assets/components/documentList/_documentList.scss b/client/assets/components/documentList/_documentList.scss index 2cb303b5..cc3bae9a 100644 --- a/client/assets/components/documentList/_documentList.scss +++ b/client/assets/components/documentList/_documentList.scss @@ -2,22 +2,10 @@ em{ background-color:$highlight-color;} } -#overlay { - visibility: hidden; - position: absolute; - left: 0px; - top: 0px; - width:100%; - height:100%; - text-align:left; - z-index: 1000; -} - -#overlay pre { - width:70%; - margin: 100px auto; - background-color: #fff; - border:1px solid #000; - padding:15px; - text-align:left; -} +.moreLikeThisText { + visibility: visible; + zoom: 1; + border: 1px solid black; + overflow-x:auto; + overflow-y:auto; +} \ No newline at end of file diff --git a/client/assets/components/documentList/documentList.html b/client/assets/components/documentList/documentList.html index e1ff7fc2..7e3bf0f8 100644 --- a/client/assets/components/documentList/documentList.html +++ b/client/assets/components/documentList/documentList.html @@ -1,11 +1,17 @@
-
Show Related Items
-
+ Related Items +
+
+
{{test.title}}
+
+
+ diff --git a/client/assets/components/documentList/documentList.js b/client/assets/components/documentList/documentList.js index 3677f6c6..d94d79f2 100644 --- a/client/assets/components/documentList/documentList.js +++ b/client/assets/components/documentList/documentList.js @@ -180,6 +180,7 @@ // Otherwise we can go ahead and return what we intended else { + vm.test = rawMoreLikeThisResults; for (var resultIndex in rawMoreLikeThisResults) { var moreLikeThisToParse = rawMoreLikeThisResults[resultIndex]; var index = parseInt(resultIndex) + 1 @@ -239,7 +240,8 @@ * @return {list} mltResults List of "more Like This" responses to the document in question */ function getMoreLikeThis(doc){ - vm.overlay(); + // vm.overlay(); + vm.docId = doc.id; var idField = ConfigService.getRecommenderIdField(); if (idField == null) { $log.debug("We don't have an id field! Setting it to id"); @@ -251,18 +253,19 @@ obj['wt'] = 'json'; // Clear the innerhtml to prevent a split second confusion - document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = ""; + // document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = ""; QueryDataService.getMoreLikeThisResults(obj, true).then(displayResults, solrError); function solrError(response) { $log.error(response); - document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = response.details; + // document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = response.details; } function displayResults(response){ + // console.log(response.response.docs); var parsedMoreLikeThisResults = manipulateResults(); $log.debug("The results are " + parsedMoreLikeThisResults); - document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = parsedMoreLikeThisResults; + // document.getElementById('MoreLikeThisResultsFromPipeline').innerHTML = parsedMoreLikeThisResults; } } }