Created
April 1, 2012 06:28
-
-
Save cute/2271982 to your computer and use it in GitHub Desktop.
Sphinx 1.10 GetDocinfo Patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -rup sphinx-1.10-beta/src/searchd.cpp 1.10/src/searchd.cpp | |
--- sphinx-1.10-beta/src/searchd.cpp 2010-07-19 23:56:34.000000000 +0800 | |
+++ 1.10/src/searchd.cpp 2011-09-01 11:39:24.000000000 +0800 | |
@@ -353,6 +353,8 @@ enum SearchdCommand_e | |
SEARCHD_COMMAND_STATUS = 5, | |
SEARCHD_COMMAND_QUERY = 6, | |
SEARCHD_COMMAND_FLUSHATTRS = 7, | |
+ SEARCHD_COMMAND_SEGMENT = 8, | |
+ SEARCHD_COMMAND_DOCINFO = 9, | |
SEARCHD_COMMAND_TOTAL | |
}; | |
@@ -367,7 +369,9 @@ enum | |
VER_COMMAND_KEYWORDS = 0x100, | |
VER_COMMAND_STATUS = 0x100, | |
VER_COMMAND_QUERY = 0x100, | |
- VER_COMMAND_FLUSHATTRS = 0x100 | |
+ VER_COMMAND_FLUSHATTRS = 0x100, | |
+ VER_COMMAND_SEGMENT = 0x100, | |
+ VER_COMMAND_DOCINFO = 0x100, | |
}; | |
@@ -5675,6 +5679,107 @@ void SendSearchResponse ( SearchHandler_ | |
SafeDeleteArray ( tHandler.m_dQueries[i].m_pWeights ); | |
} | |
+void HandleCommandDocinfo ( int iSock, int iVer, InputBuffer_c & tReq ) | |
+{ | |
+ if ( !CheckCommandVersion ( iVer, VER_COMMAND_DOCINFO, tReq ) ) | |
+ return; | |
+ | |
+ SphDocID_t uDocID = tReq.GetUint64 (); | |
+ CSphString sIndex = tReq.GetString (); | |
+ | |
+ const ServedIndex_t * pIndex = g_pIndexes->GetRlockedEntry ( sIndex ); | |
+ if ( !pIndex ) | |
+ { | |
+ tReq.SendErrorReply ( "unknown local index '%s' in search request", sIndex.cstr() ); | |
+ return; | |
+ } | |
+ | |
+ CSphQueryResult *pResult = new CSphQueryResult(); | |
+ | |
+ int iRespLen = 4; | |
+ NetOutputBuffer_c tOut ( iSock ); | |
+ tOut.SendWord ( SEARCHD_OK ); | |
+ tOut.SendWord ( VER_COMMAND_DOCINFO ); | |
+ | |
+ if (!pIndex->m_pIndex->GetDocinfo(pResult, uDocID)) | |
+ { | |
+ tOut.SendInt ( iRespLen); | |
+ tOut.SendInt ( 0 ); | |
+ tOut.Flush (); | |
+ pIndex->Unlock(); | |
+ return; | |
+ } | |
+ | |
+ const CSphMatch & tMatch = pResult->m_dMatches [0]; | |
+ const BYTE * pStrings = pResult->m_pStrings; | |
+ const int tCount = pResult->m_tSchema.GetAttrsCount(); | |
+ | |
+ iRespLen += tCount * 12; | |
+ | |
+ for ( int j = 0; j < tCount ; j++ ) | |
+ { | |
+ const CSphColumnInfo & tCol = pResult->m_tSchema.GetAttr(j); | |
+ DWORD uOffset = (DWORD) tMatch.GetAttr(tCol.m_tLocator ); | |
+ iRespLen += strlen ( tCol.m_sName.cstr()); | |
+ | |
+ if ( tCol.m_eAttrType & SPH_ATTR_MULTI ) { | |
+ const DWORD * pValues = tMatch.GetAttrMVA ( tCol.m_tLocator, pResult->m_pMva ); | |
+ if (pValues ){ | |
+ iRespLen += pValues[0] * 4; | |
+ } | |
+ } else if ( tCol.m_eAttrType==SPH_ATTR_STRING ) { | |
+ if ( uOffset ) { | |
+ iRespLen += sphUnpackStr ( pStrings + uOffset, NULL ); | |
+ } | |
+ } | |
+ } | |
+ | |
+ tOut.SendInt ( iRespLen ); | |
+ tOut.SendInt ( tCount ); | |
+ | |
+ for ( int i= 0; i< tCount; i++ ){ | |
+ const CSphColumnInfo & tCol = pResult->m_tSchema.GetAttr(i); | |
+ tOut.SendString ( tCol.m_sName.cstr() ); | |
+ tOut.SendDword ( tCol.m_eAttrType ); | |
+ } | |
+ | |
+ for ( int j = 0; j < tCount; j++ ) | |
+ { | |
+ const CSphColumnInfo & tCol = pResult->m_tSchema.GetAttr(j); | |
+ DWORD uOffset = (DWORD) tMatch.GetAttr(tCol.m_tLocator ); | |
+ if ( tCol.m_eAttrType & SPH_ATTR_MULTI ) { | |
+ const DWORD * pValues = tMatch.GetAttrMVA ( tCol.m_tLocator, pResult->m_pMva ); | |
+ if ( !pValues ){ | |
+ tOut.SendString ( 0 ); | |
+ } else { | |
+ int iValues = *pValues++; | |
+ tOut.SendDword ( iValues ); | |
+ while ( iValues-- ){ | |
+ tOut.SendDword ( *pValues++ ); | |
+ } | |
+ } | |
+ } else if ( tCol.m_eAttrType==SPH_ATTR_STRING ) { | |
+ if ( !uOffset ) { | |
+ tOut.SendDword ( 0 ); // null string | |
+ } else{ | |
+ const BYTE * pStr; | |
+ int iLen = sphUnpackStr (pResult->m_pStrings + uOffset, &pStr ); | |
+ tOut.SendDword ( iLen ); | |
+ tOut.SendBytes ( pStr, iLen ); | |
+ } | |
+ } else { | |
+ if ( tCol.m_eAttrType==SPH_ATTR_FLOAT ) | |
+ tOut.SendFloat (uOffset ); | |
+ else if (tCol.m_eAttrType==SPH_ATTR_BIGINT ) | |
+ tOut.SendUint64 ( uOffset ); | |
+ else | |
+ tOut.SendDword ( uOffset ); | |
+ } | |
+ } | |
+ pIndex->Unlock(); | |
+ tOut.Flush (); | |
+} | |
+ | |
void HandleCommandSearch ( int iSock, int iVer, InputBuffer_c & tReq ) | |
{ | |
@@ -7020,6 +7125,7 @@ void HandleClientSphinx ( int iSock, con | |
switch ( iCommand ) | |
{ | |
case SEARCHD_COMMAND_SEARCH: HandleCommandSearch ( iSock, iCommandVer, tBuf ); break; | |
+ case SEARCHD_COMMAND_DOCINFO: HandleCommandDocinfo ( iSock, iCommandVer, tBuf ); break; | |
case SEARCHD_COMMAND_EXCERPT: HandleCommandExcerpt ( iSock, iCommandVer, tBuf ); break; | |
case SEARCHD_COMMAND_KEYWORDS: HandleCommandKeywords ( iSock, iCommandVer, tBuf ); break; | |
case SEARCHD_COMMAND_UPDATE: HandleCommandUpdate ( iSock, iCommandVer, tBuf, iPipeFD ); break; | |
diff -rup sphinx-1.10-beta/src/sphinx.cpp 1.10/src/sphinx.cpp | |
--- sphinx-1.10-beta/src/sphinx.cpp 2010-07-19 17:21:37.000000000 +0800 | |
+++ 1.10/src/sphinx.cpp 2011-09-01 13:07:19.000000000 +0800 | |
@@ -1241,6 +1241,7 @@ public: | |
virtual SphAttr_t * GetKillList () const; | |
virtual int GetKillListSize () const { return m_iKillListSize; } | |
virtual bool HasDocid ( SphDocID_t uDocid ) const; | |
+ virtual bool GetDocinfo (CSphQueryResult *pResult, SphDocID_t uDocid ) const; | |
virtual const CSphSourceStats & GetStats () const { return m_tStats; } | |
@@ -11109,6 +11110,29 @@ bool CSphIndex_VLN::HasDocid ( SphDocID_ | |
return FindDocinfo ( uDocid )!=NULL; | |
} | |
+bool CSphIndex_VLN::GetDocinfo (CSphQueryResult *pResult, SphDocID_t uDocid ) const | |
+{ | |
+ const DWORD * pFound = FindDocinfo ( uDocid ); | |
+ | |
+ if ( !pFound ) | |
+ return false; | |
+ | |
+ CSphSwapVector<CSphMatch> m_dMatches; | |
+ | |
+ m_dMatches.Add(); | |
+ m_dMatches[0].m_iDocID = uDocid; | |
+ m_dMatches[0].m_pStatic = DOCINFO2ATTRS(pFound); | |
+ | |
+ pResult->m_pStrings = m_pStrings.GetWritePtr(); | |
+ pResult->m_pMva = m_pMva.GetWritePtr(); | |
+ pResult->m_tSchema = m_tSchema; | |
+ pResult->m_dMatches = m_dMatches; | |
+ pResult->m_iCount = 1; | |
+ pResult->m_pAttrs = (CSphRowitem *) DOCINFO2ATTRS(pFound); | |
+ | |
+ return true; | |
+} | |
+ | |
const DWORD * CSphIndex_VLN::FindDocinfo ( SphDocID_t uDocID ) const | |
{ | |
diff -rup sphinx-1.10-beta/src/sphinx.h 1.10/src/sphinx.h | |
--- sphinx-1.10-beta/src/sphinx.h 2010-07-19 07:22:48.000000000 +0800 | |
+++ 1.10/src/sphinx.h 2011-09-01 11:29:10.000000000 +0800 | |
@@ -2267,6 +2267,7 @@ public: | |
virtual SphAttr_t * GetKillList () const = 0; | |
virtual int GetKillListSize () const = 0; | |
virtual bool HasDocid ( SphDocID_t uDocid ) const = 0; | |
+ virtual bool GetDocinfo ( CSphQueryResult *pResult, SphDocID_t uDocid ) const = 0; | |
public: | |
/// build index by indexing given sources | |
diff -rup sphinx-1.10-beta/src/sphinxrt.cpp 1.10/src/sphinxrt.cpp | |
--- sphinx-1.10-beta/src/sphinxrt.cpp 2010-07-19 23:42:32.000000000 +0800 | |
+++ 1.10/src/sphinxrt.cpp 2011-09-01 11:26:58.000000000 +0800 | |
@@ -1003,6 +1003,7 @@ public: | |
virtual SphAttr_t * GetKillList () const { return NULL; } | |
virtual int GetKillListSize () const { return 0; } | |
virtual bool HasDocid ( SphDocID_t ) const { assert ( 0 ); return false; } | |
+ virtual bool GetDocinfo (CSphQueryResult *pResult ,SphDocID_t uDocid) const { assert ( 0 ); return false; } | |
virtual int Build ( const CSphVector<CSphSource*> & dSources, int iMemoryLimit, int iWriteBuffer ) { return 0; } | |
virtual bool Merge ( CSphIndex * pSource, CSphVector<CSphFilterSettings> & dFilters, bool bMergeKillLists ) { return false; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment