PHP Velho Oeste 2024

SphinxClient::setServer

(PECL sphinx >= 0.1.0)

SphinxClient::setServerConfigure l'hôte et le port searchd

Description

public SphinxClient::setServer ( string $server , int $port ) : bool

Configure l'hôte et le port searchd. Toutes les requêtes suivantes seront envoyées au nouvel hôte. Par défaut, l'hôte et le port sont 'localhost' et 3312, respectivement.

Liste de paramètres

server

IP ou nom d'hôte.

port

Numéro de port.

Valeurs de retour

Cette fonction retourne TRUE en cas de succès ou FALSE si une erreur survient.

add a note add a note

User Contributed Notes 1 note

up
-11
craig dot constable at gmail dot com
11 years ago
<?php
   
//Here is an example of using the Sphinx api client
   
$server = "192.168.0.100:3306";
   
$username = "johnsmith";
   
$password = "Password1";
   
$database = "customers";
    function
newSQL() {
        global
$server, $username, $password, $database;
       
$con = new mysqli($server, $username, $password, $database);
        return
$con;
    }

    include(
'sphinxapi.php');

   
$search = '@postcode 2012';
   
$s = new SphinxClient;
   
$s->SetServer("192.168.0.100", 9312);
   
$s->SetMatchMode(SPH_MATCH_EXTENDED2);
   
$s->SetSortMode (SPH_SORT_EXTENDED,'@random');
   
$s->SetLimits(0, $times);
   
$index = 'main:delta';
   
$result = $s->Query($search, $index);

    if (
$result['total'] > 0) {
        foreach (
$result['matches'] as $id => $other) {
           
$people .= "pid=$id OR ";   
        }
       
$people = substr($people, 0, -4);
    }

   
$mysqli = newSQL();
   
$mysqliResult = $mysqli->query("SELECT `pid`, `name`, `postcode` FROM `profiles` WHERE ($people)");
   
//Do something with $mysqliResult
   
$mysqli->close();
?>
To Top