diff --git a/HttpMime.cpp b/HttpMime.cpp index 756f4c09..cd10cfd5 100644 --- a/HttpMime.cpp +++ b/HttpMime.cpp @@ -691,6 +691,7 @@ void HttpMime::makeMime ( long totalContentLen , "HTTP/1.0 %li%s\r\n" "Date: %s\r\n" //"P3P: CP=\"CAO PSA OUR\"\r\n" + "Access-Control-Allow-Origin: *\r\n" "Server: Gigablast/1.0\r\n" "Content-Length: %li\r\n" //"Expires: Wed, 23 Dec 2003 10:23:01 GMT\r\n" @@ -722,6 +723,8 @@ void HttpMime::makeMime ( long totalContentLen , "Content-Range: %li-%li(%li)\r\n"// added "bytes" "Connection: Close\r\n" //"P3P: CP=\"CAO PSA OUR\"\r\n" + // for ajax support + "Access-Control-Allow-Origin: *\r\n" "Server: Gigablast/1.0\r\n" "%s" "Date: %s\r\n" @@ -768,6 +771,7 @@ void HttpMime::makeMime ( long totalContentLen , //"Connection: Keep-Alive\r\n" "Connection: Close\r\n" //"P3P: CP=\"CAO PSA OUR\"\r\n" + "Access-Control-Allow-Origin: *\r\n" "Server: Gigablast/1.0\r\n" "%s" "Date: %s\r\n" diff --git a/PageResults.cpp b/PageResults.cpp index 52e9fbed..c8f75eeb 100644 --- a/PageResults.cpp +++ b/PageResults.cpp @@ -904,25 +904,134 @@ bool gotResults ( void *state ) { // + SafeBuf *sb = &st->m_sb; + + // print javascript for scrolling down invisible div for + // ajax based widgets + if ( si->m_format == FORMAT_WIDGET_AJAX ) { + sb->safePrintf("" + ); + } + + // print logo, search box, results x-y, ... into st->m_sb printSearchResultsHeader ( st ); + + // if user is doing ajax widget we need to know the current docid + // that is listed at the top of their widget display so we can + // hide the new docids above that and scroll them down slowly. + long numResults = msg40->getNumResults(); + long topDocIdPos = -1; + bool hasInvisibleResults = false; + HttpRequest *hr = &st->m_hr; + long long oldTop = 0LL; + if ( si->m_format == FORMAT_WIDGET_AJAX ) { + // get current top docid + long long topDocId = hr->getLongLong("topdocid",0LL); + // scan results + for ( long i = 0 ; i < numResults ; i++ ) { + // no point if no top docid + if ( topDocId == 0 ) break; + // get it + Msg20 *m20 ; + if ( si->m_streamResults ) + m20 = msg40->getCompletedSummary(i); + else + m20 = msg40->m_msg20[i]; + // checkdocid + Msg20Reply *mr = m20->m_r; + if ( ! mr ) continue; + if ( ! oldTop ) oldTop = mr->m_docId; + if ( mr->m_docId != topDocId ) { + hasInvisibleResults = true; + continue; + } + topDocIdPos = i; + break; + } + } + + + // propagate "topdocid" so when he does another query every 30 secs + // or so we know what docid was on top for scrolling purposes + if ( si->m_format == FORMAT_WIDGET_AJAX ) + sb->safePrintf("\n\n", + oldTop); + + // then print each result // don't display more than docsWanted results long count = msg40->getDocsWanted(); bool hadPrintError = false; - long numResults = msg40->getNumResults(); + long widgetHeight = hr->getLong("widgetheight",400); for ( long i = 0 ; count > 0 && i < numResults ; i++ ) { + + if ( hasInvisibleResults ) { + // + // MAKE THESE RESULTS INVISIBLE! + // + // if doing a widget, we initially hide the new results + // and scroll them down in time so it looks cool. + if ( i == 0 ) + sb->safePrintf("