(8)查询和自动补全

这个类对前段提交的查询进行分类处理,如果是查询则返回翻译,如果是发送的补全提示,则返回最近接用户输入的前10个单词,供用户选择


<?php
require_once "storeWord.class.php";
require_once "filterword.class.php";
require_once "format.class.php";
require_once "processCheck.class.php";
require_once "cookie.php";
require_once "sql.class.php";
require_once "./addword/addredis.class.php";
header("Content-type: plain/text; charset=utf-8");
header("Cache-control:no-store");
if(!empty($_GET['enword']))
{
	$en=strtolower(trim($_GET['enword']));
	$filter = new Filter($en);
	$en=$filter->getResult();
	$check = new Check();
	$translation = new FormatTrans;
	
	//返回ajax查询结果
	if($_GET['type']==1)
	{
		$redis=new StoreWord();
		$addredis = new AddRedis();
		$wordZone=$check->matchDic($en);
		
		//将查询过的单词根据cookie写入到数据库
	 	$username=setOrGetUser();
		$sql = new Sql($username, $en);
		//$sql->setWord($en); 
		
		$ch=$redis->getWord($wordZone,$en);
		$res['flag']=1;
		
		$trans='';
		if($ch===0)
		{
			//从redis中找到用户添加的单词对应的ID,并根据此ID从MySQL中找到用户添加的词条对应的翻译
			$chinese = $addredis->getTrans($en);
			$trans = ($chinese == 0 ? array("没有找到对应的翻译") : $chinese);
			//$trans = array("没有找到对应的翻译");
		}
		else
		{
			$trans = $translation->trans($ch);
		}
		$res['result']=$trans;
		echo json_encode($res);
	}
	//返回ajax自动补全集
	else if($_GET['type']==2)
	{
		$matchWord=$check->ajaxMatch($en);
		//file_put_contents("word.txt", $en."---".serialize($matchWord)."\r\n", FILE_APPEND);
		$res['flag']=2;
		$res['result']=$matchWord;
		echo json_encode($res);
	}
}
else
{
	file_put_contents('log.txt', "receive NON data \r\n",FILE_APPEND);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值