From c8f305468f6446c3b7f6a7ec180b96737cfdbc69 Mon Sep 17 00:00:00 2001
From: Matt <mwells2@gigablast.com>
Date: Thu, 11 Dec 2014 13:13:50 -0800
Subject: [PATCH] fix facet bug

---
 Makefile  | 4 ++--
 Msg39.cpp | 2 ++
 Msg40.cpp | 2 +-
 Posdb.cpp | 7 +++++--
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 42061f99..20b7134a 100644
--- a/Makefile
+++ b/Makefile
@@ -409,8 +409,8 @@ IndexTable.o:
 IndexTable2.o:
 	$(CC) $(DEFS) $(CPPFLAGS) -O2 -c $*.cpp 
 
-#Posdb.o:
-#	$(CC) $(DEFS) $(CPPFLAGS) -O2 -c $*.cpp 
+Posdb.o:
+	$(CC) $(DEFS) $(CPPFLAGS) -O2 -c $*.cpp 
 
 # Query::setBitScores() needs this optimization
 #Query.o:
diff --git a/Msg39.cpp b/Msg39.cpp
index 78b0ec96..ca49e29d 100644
--- a/Msg39.cpp
+++ b/Msg39.cpp
@@ -1497,6 +1497,8 @@ void Msg39::estimateHitsAndSendReply ( ) {
 				// lookup the text of the facet in Msg40.cpp
 				FacetEntry *fe;
 				fe = (FacetEntry *)ft->getValFromSlot(k);
+				// sanity
+				if ( fe->m_count == 0 ) { char *xx=NULL;*xx=0;}
 				memcpy ( p , fe , sizeof(FacetEntry) );
 				p += sizeof(FacetEntry);
 				// do not breach
diff --git a/Msg40.cpp b/Msg40.cpp
index 7881dbab..9a29d8b8 100644
--- a/Msg40.cpp
+++ b/Msg40.cpp
@@ -6519,7 +6519,7 @@ bool Msg40::printFacetsForTable ( SafeBuf *sb , QueryTerm *qt ) {
 				       , count );
 
 			// if it's a # then we print stats after
-			if ( isString )
+			if ( isString || fe->m_count == 0 )
 				sb->safePrintf("\n");
 			else
 				sb->safePrintf(",\n");
diff --git a/Posdb.cpp b/Posdb.cpp
index cccc3761..31e5b6db 100644
--- a/Posdb.cpp
+++ b/Posdb.cpp
@@ -7284,7 +7284,6 @@ void PosdbTable::intersectLists10_r ( ) {
 			//qt->m_facetHashTable.addTerm32(&val32
 			// get it
 			HashTableX *ft = &qt->m_facetHashTable;
-			FacetEntry *fe;
 			fe=(FacetEntry *)ft->getValue(&val32);
 			// debug 
 			//log("facets: got entry for key=%"UINT32" "
@@ -7299,7 +7298,11 @@ void PosdbTable::intersectLists10_r ( ) {
 					char *xx=NULL;*xx=0; }
 				memset ( &ff , 0 , sizeof(FacetEntry) );
 				fe = &ff;
-				ft->addKey(&val32,fe);
+				int32_t slot;
+				ft->addKey(&val32,fe,&slot);
+				// now point to what we added since
+				// we increment count below, add min/max, etc.
+				fe = (FacetEntry *)ft->getValueFromSlot(slot);
 			}
 		}