fix invalid json when doing &s=1
This commit is contained in:
10
Msg40.cpp
10
Msg40.cpp
@ -100,6 +100,7 @@ Msg40::Msg40() {
|
||||
m_sendsIn = 0;
|
||||
m_printi = 0;
|
||||
m_numDisplayed = 0;
|
||||
m_numPrintedSoFar = 0;
|
||||
m_lastChunk = false;
|
||||
//m_numGigabitInfos = 0;
|
||||
}
|
||||
@ -1683,6 +1684,7 @@ bool Msg40::gotSummary ( ) {
|
||||
if ( m_si && m_numDisplayed <= m_si->m_firstResultNum ){
|
||||
log("msg40: hiding #%li (%lu)",
|
||||
m_printi,mr->m_contentHash32);
|
||||
m20->reset();
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1690,7 +1692,9 @@ bool Msg40::gotSummary ( ) {
|
||||
|
||||
// . ok, we got it, so print it and stream it
|
||||
// . this might set m_hadPrintError to true
|
||||
printSearchResult9 ( m_printi );
|
||||
printSearchResult9 ( m_printi , m_numPrintedSoFar );
|
||||
|
||||
m_numPrintedSoFar++;
|
||||
|
||||
// now free the reply to save memory since we could be
|
||||
// streaming back 1M+. we call reset below, no need for this.
|
||||
@ -5175,7 +5179,7 @@ bool Msg40::addFacts ( HashTableX *queryTable,
|
||||
|
||||
|
||||
// . printSearchResult into "sb"
|
||||
bool Msg40::printSearchResult9 ( long ix ) {
|
||||
bool Msg40::printSearchResult9 ( long ix , long numPrintedSoFar ) {
|
||||
|
||||
// . we stream results right onto the socket
|
||||
// . useful for thousands of results... and saving mem
|
||||
@ -5202,7 +5206,7 @@ bool Msg40::printSearchResult9 ( long ix ) {
|
||||
}
|
||||
|
||||
// print that out into st->m_sb safebuf
|
||||
else if ( ! printResult ( st , ix ) ) {
|
||||
else if ( ! printResult ( st , ix , numPrintedSoFar ) ) {
|
||||
// oom?
|
||||
if ( ! g_errno ) g_errno = EBADENGINEER;
|
||||
log("query: had error: %s",mstrerror(g_errno));
|
||||
|
3
Msg40.h
3
Msg40.h
@ -208,7 +208,7 @@ class Msg40 {
|
||||
|
||||
long m_lastHeartbeat;
|
||||
|
||||
bool printSearchResult9 ( long ix ) ;
|
||||
bool printSearchResult9 ( long ix , long numPrintedSoFar ) ;
|
||||
HashTableX m_columnTable;
|
||||
bool printCSVHeaderRow ( class SafeBuf *sb );
|
||||
bool printJsonItemInCSV ( class State0 *st , long ix );
|
||||
@ -265,6 +265,7 @@ class Msg40 {
|
||||
long m_sendsIn ;
|
||||
long m_printi ;
|
||||
long m_numDisplayed ;
|
||||
long m_numPrintedSoFar;
|
||||
long m_socketHadError;
|
||||
|
||||
|
||||
|
@ -1001,6 +1001,7 @@ bool gotResults ( void *state ) {
|
||||
// don't display more than docsWanted results
|
||||
long count = msg40->getDocsWanted();
|
||||
bool hadPrintError = false;
|
||||
long numPrintedSoFar = 0;
|
||||
//long widgetHeight = hr->getLong("widgetheight",400);
|
||||
//long widgetwidth = hr->getLong("widgetwidth",250);
|
||||
|
||||
@ -1044,7 +1045,7 @@ bool gotResults ( void *state ) {
|
||||
// prints in xml or html
|
||||
//
|
||||
//////////
|
||||
if ( ! printResult ( st , i ) ) {
|
||||
if ( ! printResult ( st , i , numPrintedSoFar++ ) ) {
|
||||
hadPrintError = true;
|
||||
break;
|
||||
}
|
||||
@ -2359,7 +2360,7 @@ static bool printDMOZCategoryUnderResult ( SafeBuf *sb ,
|
||||
|
||||
|
||||
// use this for xml as well as html
|
||||
bool printResult ( State0 *st, long ix ) {
|
||||
bool printResult ( State0 *st, long ix , long numPrintedSoFar ) {
|
||||
|
||||
SafeBuf *sb = &st->m_sb;
|
||||
|
||||
@ -2440,7 +2441,7 @@ bool printResult ( State0 *st, long ix ) {
|
||||
if ( mr->ptr_content ) {
|
||||
|
||||
// for json items separate with \n,\n
|
||||
if ( si->m_format != FORMAT_HTML && ix>0 )
|
||||
if ( si->m_format != FORMAT_HTML && numPrintedSoFar > 0 )
|
||||
sb->safePrintf(",\n");
|
||||
|
||||
sb->safeStrcpy ( mr->ptr_content );
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
|
||||
|
||||
bool printSearchResultsHeader ( class State0 *st ) ;
|
||||
bool printResult ( class State0 *st, long ix );
|
||||
bool printResult ( class State0 *st, long ix , long numPrintedSoFar );
|
||||
bool printSearchResultsTail ( class State0 *st ) ;
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user