How to connect coreseek in php

墨辰丷
Release: 2023-03-25 19:02:01
Original
1459 people have browsed it

This article mainly introduces an example of combining php and coreseek. Friends who are interested in how to connect php to coreseek can refer to it.

The following is the code

<?php
require_once AN_ROOT."/inc/sphinxapi.php";
require_once AN_ROOT."/res/adodb/adodb.inc.php";
$keywords = $_REQUEST[&#39;keywords&#39;];

$info    = getInfoCoreSeek($keywords,$_GET[&#39;page&#39;]);

function getInfoCoreSeek($keywords,$page=1) {
    $mode = SPH_MATCH_ANY;
    $host = "localhost";
    $port = 3312;
    $index = "*";
    $limit = 4;
    $ranker = SPH_RANK_PROXIMITY_BM25;

    if(!$page) $page=1;
    $page = intval($page);
    $off = ($page-1)*$limit;

    $cl = new SphinxClient ();
    $cl->SetServer ( $host, $port );
    $cl->SetConnectTimeout ( 1 );
    $cl->SetWeights ( array ( 100, 1 ) );
    $cl->SetMatchMode ( $mode );
    $cl->SetLimits ( $off, $limit, ( $limit>10000 ) ? $limit : 10000 );
    $cl->SetRankingMode ( $ranker );
    $cl->SetArrayResult ( true );
    $res    = $cl->Query ( join(" ", $keywords), $index );
    if($res) {
        $pageL    = PageQuery($res[&#39;total&#39;],$page,4,"act=search&keywords=".$_REQUEST[&#39;keywords&#39;]);
        foreach($res[&#39;matches&#39;] as $v) {
            $arrID[]    = $v[&#39;id&#39;];    
        }
        $rs    = $GLOBALS[&#39;db&#39;]->GetAll("select id,title,content from info where id in(".join(&#39;,&#39;, $arrID).")");
        $GLOBALS[&#39;tpl&#39;]->assign(&#39;pageL&#39;, $pageL);
        //echo &#39;<pre class="brush:php;toolbar:false">&#39;;
        //print_r($res);
        //echo &#39;
'; return $rs; } } ?>
Copy after login

Related recommendations:

Compile and install Sphinx, Chinese word segmentation coreseek and PHP's sphinx extension

coreseek (sphinx) Mysql Thinkphp Detailed explanation of building a Chinese search engine

coreseek configuration and incremental index merge index

The above is the detailed content of How to connect coreseek in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!