Skip to content

Commit

Permalink
added FlushAttrs() command and API call, updated PHP/Python/Java APIs
Browse files Browse the repository at this point in the history
added --logdebug option to searchd



git-svn-id: http://sphinxsearch.googlecode.com/svn/trunk@2011 8b96e2b9-35c5-2c16-bc47-5122d61876d4
  • Loading branch information
shodan committed Oct 1, 2009
1 parent bf6d928 commit 9fac88d
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 52 deletions.
33 changes: 33 additions & 0 deletions api/java/SphinxClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ public class SphinxClient
private final static int SEARCHD_COMMAND_UPDATE = 2;
private final static int SEARCHD_COMMAND_KEYWORDS = 3;
private final static int SEARCHD_COMMAND_PERSIST = 4;
private final static int SEARCHD_COMMAND_FLUSHATTRS = 7;

/* searchd command versions */
private final static int VER_MAJOR_PROTO = 0x1;
private final static int VER_COMMAND_SEARCH = 0x117;
private final static int VER_COMMAND_EXCERPT = 0x100;
private final static int VER_COMMAND_UPDATE = 0x101;
private final static int VER_COMMAND_KEYWORDS = 0x100;
private final static int VER_COMMAND_FLUSHATTRS = 0x100;

/* filter types */
private final static int SPH_FILTER_VALUES = 0;
Expand Down Expand Up @@ -1289,6 +1291,37 @@ public Map[] BuildKeywords ( String query, String index, boolean hits ) throws S
}
}



/**
* Force attribute flush, and block until it completes.
* Returns current internal flush tag on success, -1 on failure.
*/
public int FlushAttrs() throws SphinxException
{
/* build request */
ByteArrayOutputStream reqBuf = new ByteArrayOutputStream();

/* run request */
DataInputStream in = _DoRequest ( SEARCHD_COMMAND_FLUSHATTRS, VER_COMMAND_FLUSHATTRS, reqBuf );
if ( in==null )
return -1;

/* parse reply */
try
{
int iFlushTag = in.readInt ();
return iFlushTag;

} catch ( Exception e )
{
_error = "incomplete reply";
return -1;
}
}



/** Escape the characters with special meaning in query syntax. */
static public String EscapeString ( String s )
{
Expand Down
46 changes: 39 additions & 7 deletions api/sphinxapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
/////////////////////////////////////////////////////////////////////////////

/// known searchd commands
define ( "SEARCHD_COMMAND_SEARCH", 0 );
define ( "SEARCHD_COMMAND_EXCERPT", 1 );
define ( "SEARCHD_COMMAND_UPDATE", 2 );
define ( "SEARCHD_COMMAND_KEYWORDS",3 );
define ( "SEARCHD_COMMAND_PERSIST", 4 );
define ( "SEARCHD_COMMAND_STATUS", 5 );
define ( "SEARCHD_COMMAND_QUERY", 6 );
define ( "SEARCHD_COMMAND_SEARCH", 0 );
define ( "SEARCHD_COMMAND_EXCERPT", 1 );
define ( "SEARCHD_COMMAND_UPDATE", 2 );
define ( "SEARCHD_COMMAND_KEYWORDS", 3 );
define ( "SEARCHD_COMMAND_PERSIST", 4 );
define ( "SEARCHD_COMMAND_STATUS", 5 );
define ( "SEARCHD_COMMAND_QUERY", 6 );
define ( "SEARCHD_COMMAND_FLUSHATRS", 7 );

/// current client-side command implementation versions
define ( "VER_COMMAND_SEARCH", 0x117 );
Expand All @@ -33,6 +34,7 @@
define ( "VER_COMMAND_KEYWORDS", 0x100 );
define ( "VER_COMMAND_STATUS", 0x100 );
define ( "VER_COMMAND_QUERY", 0x100 );
define ( "VER_COMMAND_FLUSHATTRS", 0x100 );

/// known searchd status codes
define ( "SEARCHD_OK", 0 );
Expand Down Expand Up @@ -1604,6 +1606,36 @@ function Status ()
$this->_MBPop ();
return $res;
}

//////////////////////////////////////////////////////////////////////////
// flush
//////////////////////////////////////////////////////////////////////////

function FlushAttrs ()
{
$this->_MBPush ();
if (!( $fp = $this->_Connect() ))
{
$this->_MBPop();
return false;
}

$req = pack ( "nnN", SEARCHD_COMMAND_FLUSHATTRS, VER_COMMAND_FLUSHATTRS, 0 ); // len=0
if ( !( $this->_Send ( $fp, $req, 8 ) ) ||
!( $response = $this->_GetResponse ( $fp, VER_COMMAND_FLUSHATTRS ) ) )
{
$this->_MBPop ();
return false;
}

$tag = -1;
if ( strlen($response)==4 )
list(,$tag) = unpack ( "N*", $response );

$this->_MBPop ();
return $tag;
}

}

//
Expand Down
28 changes: 23 additions & 5 deletions api/sphinxapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@


# known searchd commands
SEARCHD_COMMAND_SEARCH = 0
SEARCHD_COMMAND_EXCERPT = 1
SEARCHD_COMMAND_UPDATE = 2
SEARCHD_COMMAND_KEYWORDS= 3
SEARCHD_COMMAND_PERSIST = 4
SEARCHD_COMMAND_SEARCH = 0
SEARCHD_COMMAND_EXCERPT = 1
SEARCHD_COMMAND_UPDATE = 2
SEARCHD_COMMAND_KEYWORDS = 3
SEARCHD_COMMAND_PERSIST = 4
SEARCHD_COMMAND_FLUSHATTRS = 7

# current client-side command implementation versions
VER_COMMAND_SEARCH = 0x116
VER_COMMAND_EXCERPT = 0x100
VER_COMMAND_UPDATE = 0x101
VER_COMMAND_KEYWORDS = 0x100
VER_COMMAND_FLUSHATTRS = 0x100

# known searchd status codes
SEARCHD_OK = 0
Expand Down Expand Up @@ -964,6 +966,22 @@ def Close(self):
def EscapeString(self, string):
return re.sub(r"([=\(\)|\-!@~\"&/\\\^\$\=])", r"\\\1", string)


def FlushAttrs(self):
sock = self._Connect()
if not sock:
return None

request = pack ( '>hhI', SEARCHD_COMMAND_FLUSHATTRS, VER_COMMAND_FLUSHATTRS, 0 ) # cmd, ver, bodylen
sock.send ( request )

response = self._GetResponse ( sock, VER_COMMAND_FLUSHATTRS )
if not response or len(response)!=4:
return -1

tag = unpack ( '>L', response[0:4] )[0]
return tag

#
# $Id$
#
Loading

0 comments on commit 9fac88d

Please sign in to comment.