added broad search exception
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 9 May 2005 21:52:05 +0000 (21:52 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 9 May 2005 21:52:05 +0000 (21:52 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@689 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/javascript/opac/AbstractRecordResultPage.js
Open-ILS/src/javascript/opac/MRResultPage.js

index 094836a..6c582a4 100644 (file)
@@ -60,6 +60,7 @@ AbstractRecordResultPage.prototype.resetPage = function() {
 
        this.requestBatch = new RequestBatch();
        this.finalized = false;
+       this.builtLinks = false;
 }
 
 AbstractRecordResultPage.prototype.resetSearch = function() {
@@ -67,12 +68,15 @@ AbstractRecordResultPage.prototype.resetSearch = function() {
        this.ranks                                      = new Array();
        this.hitCount                           = 0;                                    /* hits for the current search */
        this.searchOffset                       = 0;                                    /* the offset for the search display */
+       this.page                                       = 0;
 
 }
 
 AbstractRecordResultPage.prototype.gatherIDs = function(result) {
+       if(result == null) return;
 
        this.hitCount = parseInt(result.count);
+
        if(this.hitCount < 1 ) {
                this.finalizePage();
                return false;
@@ -122,6 +126,8 @@ AbstractRecordResultPage.prototype.complete = function() {
 AbstractRecordResultPage.prototype.displayRecord = 
        function( record, search_id, page_id ) {
 
+       if(record == null) return;
+
        if(page_id == 0)
                this.buildNextLinks();
 
@@ -240,9 +246,13 @@ AbstractRecordResultPage.prototype.displayRecord =
 AbstractRecordResultPage.prototype.mkAuthorLink = function(auth) {
        var href = createAppElement("a");
        add_css_class(href,"record_result_sidebar_link");
+
        href.setAttribute("href",
                "?target=mr_result&mr_search_type=author&page=0&mr_search_query=" +
-               encodeURIComponent(auth));
+               encodeURIComponent(auth) +
+               "&mr_search_depth=" + this.searchDepth +
+               "&mr_search_location=" + this.searchLocation);
+
        href.appendChild(createAppTextNode(auth));
        return href;
 }
@@ -252,7 +262,9 @@ AbstractRecordResultPage.prototype.mkSubjectLink = function(sub) {
        add_css_class(href,"record_result_sidebar_link");
        href.setAttribute("href",
                "?target=mr_result&mr_search_type=subject&page=0&mr_search_query=" +
-               encodeURIComponent(sub));
+               encodeURIComponent(sub) + 
+               "&mr_search_depth=" + this.searchDepth +
+               "&mr_search_location=" + this.searchLocation);
        href.appendChild(createAppTextNode(sub));
        return href;
 }
@@ -348,6 +360,11 @@ AbstractRecordResultPage.prototype.displayCopyCounts =
 
 AbstractRecordResultPage.prototype.buildNextLinks = function() {
 
+       if(this.builtLinks)
+               return;
+       this.builtLinks = true;
+
+
 
        var obj = this;
        var next;
index 0728f2f..d67d337 100644 (file)
@@ -79,7 +79,8 @@ MRResultPage.prototype.prev = function() {
 MRResultPage.prototype.addMenuItems = function(menu, record) {
                menu.addItem("View Metarecord Details", 
                                                        function() { alert(record.doc_id()); });
-                               xulEvtMRResultDisplayed( menu, record );
+               if(isXUL())
+                       xulEvtMRResultDisplayed( menu, record );
 }
 
 
@@ -117,6 +118,8 @@ MRResultPage.prototype.mkLink = function(id, type, value) {
 MRResultPage.prototype.doSearch = function() {
 
 
+       debug("XUL IS " + isXUL() );
+
        var string                      = paramObj.__mr_search_query;
        var stype                       = paramObj.__mr_search_type;
        var location            = paramObj.__mr_search_location;
@@ -127,6 +130,10 @@ MRResultPage.prototype.doSearch = function() {
 
        if(depth == null)
                depth = globalSearchDepth;
+
+       if(depth == null)
+               depth = findOrgDepth(globalLocation.ou_type());
+
        if(location == null)
                location = globalLocation.id();
 
@@ -174,28 +181,74 @@ MRResultPage.prototype.doSearch = function() {
                        + " and offset " + this.searchOffset  +
                        " depth: " + depth + " location: " + location);
 
+       debug("gathering the search count\n");
 
 
-       var request = new RemoteRequest( 
-                       "open-ils.search", "open-ils.search.biblio.class", 
-                       this.stype, this.string, 
-                       this.searchLocation, 
-                       this.searchDepth, "50", this.searchOffset );
+       if(this.searchOffset > 0) {
+               this.buildNextLinks();
+               this.doMRSearch();
+
+       } else {
+
+               var creq = new RemoteRequest(
+                       "open-ils.search", "open-ils.search.biblio.class.count",
+                       this.stype, this.string, this.searchLocation, this.searchDepth );
+       
+               /* this request grabs the search count.  When the counts come back
+                       the metarecord ids are collected */
+               var obj = this;
+               creq.setCompleteCallback(
+                       function(req) {
+
+                               try {
+                                       obj.hitCount = req.getResultObject();   
+
+                               } catch(E) {
+                                       if(instanceOf(E, ex)) {
+                                               alert(E.err_msg());
+                                               return;
+                                       }
+                                       else throw E;
+                               }
+
+                               obj.buildNextLinks();
+                               obj.doMRSearch();       
+                               debug("Kicking off the record id's request");
+                                                       }
+               );
+               creq.send();
+       }
+}
+
+
+MRResultPage.prototype.doMRSearch = function() {
 
        var obj = this;
+       var method = "open-ils.search.biblio.class";
+       if( this.hitCount > 1000 )
+               method = method + ".unordered";
+
+       debug("Search method is " + method);
+
+       var request = new RemoteRequest( 
+               "open-ils.search", method,
+               obj.stype, obj.string, 
+               obj.searchLocation, 
+               obj.searchDepth, "100", obj.searchOffset );
+       
        request.setCompleteCallback(
                function(req) {
                        var result = req.getResultObject();
+                       result.count = obj.hitCount;
                        obj.gatherIDs(result) 
                        obj.collectRecords();
                        obj.requestBatch.remove(req);
                }
        );
-
-       this.requestBatch.add(request);
+       obj.requestBatch.add(request);
        request.send();
-}
 
+}
 
 MRResultPage.prototype.collectRecords = function() {