mirror of
https://github.com/gigablast/open-source-search-engine.git
synced 2024-10-04 12:17:35 +03:00
print facets for each search result
This commit is contained in:
parent
1af75c5d88
commit
5ae476f34e
@ -3677,6 +3677,33 @@ bool printResult ( State0 *st, long ix , long *numPrintedSoFar ) {
|
||||
}
|
||||
|
||||
|
||||
///////////
|
||||
//
|
||||
// print facet field/values
|
||||
//
|
||||
// if there was a gbfacet*: term (gbfacetstr, gbfacetfloat, gbfacetint)
|
||||
// this should be non-NULL and have the facet field/value pairs
|
||||
// and every string ends in a \0
|
||||
//
|
||||
//////////
|
||||
char *fp = mr->ptr_facetBuf;
|
||||
char *fpEnd = fp + mr->size_facetBuf;
|
||||
for ( ; fp && fp < fpEnd ; ) {
|
||||
// print first one
|
||||
sb->safePrintf("<i><font color=maroon>");
|
||||
sb->safeStrcpy(fp);
|
||||
sb->safePrintf("</font></i>");
|
||||
sb->safePrintf(" : ");
|
||||
sb->safePrintf("<b>");
|
||||
fp += gbstrlen(fp) + 1;
|
||||
sb->htmlEncode(fp);
|
||||
// begin a new pair
|
||||
sb->safePrintf("</b>");
|
||||
sb->safeStrcpy("<br>\n");
|
||||
fp += gbstrlen(fp) + 1;
|
||||
}
|
||||
|
||||
|
||||
////////////
|
||||
//
|
||||
// print the URL
|
||||
|
@ -3212,6 +3212,10 @@ bool SafeBuf::uncompress() {
|
||||
|
||||
bool SafeBuf::safeTruncateEllipsis ( char *src , long maxLen ) {
|
||||
long srcLen = gbstrlen(src);
|
||||
return safeTruncateEllipsis ( src , srcLen , maxLen );
|
||||
}
|
||||
|
||||
bool SafeBuf::safeTruncateEllipsis ( char *src , long srcLen , long maxLen ) {
|
||||
long printLen = srcLen;
|
||||
if ( printLen > maxLen ) printLen = maxLen;
|
||||
if ( ! safeMemcpy ( src , printLen ) )
|
||||
|
@ -67,6 +67,8 @@ struct SafeBuf {
|
||||
void filterQuotes();
|
||||
bool truncateLongWords ( char *src, long srcLen , long minmax );
|
||||
bool safeTruncateEllipsis ( char *src , long maxLen );
|
||||
bool safeTruncateEllipsis ( char *src , long srcLen, long maxLen );
|
||||
|
||||
bool convertJSONtoXML ( long niceness , long startConvertPos );
|
||||
|
||||
bool safeDecodeJSONToUtf8 ( char *json, long jsonLen, long niceness);
|
||||
|
@ -15669,7 +15669,7 @@ bool Sections::printSectionDiv ( Section *sk , char format ) { // bool forProCog
|
||||
// some voting stats
|
||||
SectionStats *ss = &sk->m_stats;
|
||||
if ( ss->m_totalMatches )
|
||||
m_sbuf->safePrintf("_m=%li _n=%li _u=%li "
|
||||
m_sbuf->safePrintf("_s=%lim%lin%liu "
|
||||
,(long)ss->m_totalMatches
|
||||
,(long)ss->m_totalEntries
|
||||
,(long)ss->m_numUniqueVals
|
||||
|
57
XmlDoc.cpp
57
XmlDoc.cpp
@ -28671,6 +28671,8 @@ Msg20Reply *XmlDoc::getMsg20Reply ( ) {
|
||||
if ( strncasecmp(qs,"str:" ,4) == 0 ) qs += 4;
|
||||
else if ( strncasecmp(qs,"int:" ,4) == 0 ) qs += 4;
|
||||
else if ( strncasecmp(qs,"float:",6) == 0 ) qs += 6;
|
||||
else continue;
|
||||
break;
|
||||
}
|
||||
// if we had a facet, get the values it has in the doc
|
||||
if ( *qs ) {
|
||||
@ -48048,6 +48050,12 @@ bool XmlDoc::storeFacetValues ( char *qs , SafeBuf *sb ) {
|
||||
// sanity
|
||||
if ( ! m_contentTypeValid ) { char *xx=NULL;*xx=0; }
|
||||
|
||||
// if "qa" is a gbxpathsitehash123456 type of beastie then we
|
||||
// gotta scan the sections
|
||||
if ( strncasecmp(qs,"gbxpathsitehash",15) == 0 )
|
||||
return storeFacetValuesSections ( qs , sb );
|
||||
|
||||
|
||||
// if a json doc, get json field
|
||||
if ( m_contentType == CT_JSON )
|
||||
return storeFacetValuesJSON ( qs , sb );
|
||||
@ -48058,6 +48066,55 @@ bool XmlDoc::storeFacetValues ( char *qs , SafeBuf *sb ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool XmlDoc::storeFacetValuesSections ( char *qs , SafeBuf *sb ) {
|
||||
|
||||
// scan all sections
|
||||
Sections *ss = getSections();
|
||||
if ( ! ss ) return false;
|
||||
if ( ss == (void *)-1 ) { char *xx=NULL;*xx=0; }
|
||||
|
||||
Words *ww = getWords();
|
||||
if ( ! ww ) return false;
|
||||
if ( ww == (void *)-1 ) { char *xx=NULL;*xx=0; }
|
||||
|
||||
long siteHash32 = *getSiteHash32();
|
||||
|
||||
// qs is like gbxpathsitehash1234567
|
||||
// so get the digit part
|
||||
char *p = qs;
|
||||
for ( ; *p && ! is_digit(*p); p++ );
|
||||
uint64_t xsh = (unsigned long long)atoll(p);
|
||||
|
||||
Section *si = ss->m_rootSection;
|
||||
//sec_t mflags = SEC_SENTENCE | SEC_MENU;
|
||||
for ( ; si ; si = si->m_next ) {
|
||||
// breathe
|
||||
QUICKPOLL(m_niceness);
|
||||
// is it a match?
|
||||
uint64_t mod;
|
||||
mod = (unsigned long)si->m_turkTagHash32;
|
||||
mod ^= (unsigned long)siteHash32;
|
||||
if ( mod != xsh ) continue;
|
||||
// . then add facet VALUE
|
||||
// . hash of the innerhtml of sentence
|
||||
// . get hash of sentences this tag contains indirectly
|
||||
unsigned long val32 = (unsigned long)si->m_indirectSentHash64;
|
||||
if ( ! val32 ) continue;
|
||||
// got one print the facet field
|
||||
if ( ! sb->safeStrcpy(qs) ) return false;
|
||||
if ( ! sb->pushChar('\0') ) return false;
|
||||
if ( ! sb->safePrintf("%lu,",val32) ) return false;
|
||||
// put ALSO print the string somewhat
|
||||
char *a = m_words.m_words[si->m_next->m_a];
|
||||
char *b = m_words.m_words[si->m_next->m_b-1];
|
||||
b += m_words.m_wordLens [si->m_next->m_b-1];
|
||||
if ( ! sb->safeTruncateEllipsis (a,b-a,160) ) return false;
|
||||
if ( ! sb->pushChar('\0') ) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool XmlDoc::storeFacetValuesHtml ( char *qs , SafeBuf *sb ) {
|
||||
|
||||
Xml *xml = getXml();
|
||||
|
7
XmlDoc.h
7
XmlDoc.h
@ -911,9 +911,10 @@ class XmlDoc {
|
||||
class HashInfo *hi ,
|
||||
char *gbsortByStr ) ;
|
||||
|
||||
bool storeFacetValues ( char *qs , class SafeBuf *sb ) ;
|
||||
bool storeFacetValuesHtml ( char *qs , class SafeBuf *sb ) ;
|
||||
bool storeFacetValuesJSON ( char *qs , class SafeBuf *sb ) ;
|
||||
bool storeFacetValues ( char *qs , class SafeBuf *sb ) ;
|
||||
bool storeFacetValuesSections ( char *qs , class SafeBuf *sb ) ;
|
||||
bool storeFacetValuesHtml ( char *qs , class SafeBuf *sb ) ;
|
||||
bool storeFacetValuesJSON ( char *qs , class SafeBuf *sb ) ;
|
||||
|
||||
// print out for PageTitledb.cpp and PageParser.cpp
|
||||
bool printDoc ( class SafeBuf *pbuf );
|
||||
|
Loading…
Reference in New Issue
Block a user