更快地搜索单词数组

发布于 2024-10-11 22:18:23 字数 875 浏览 3 评论 0原文

我想看看数据库中有多少数组。它非常慢,我想知道是否有一种方法可以在没有 for 循环的情况下搜索多个单词或整个数组。我现在正在挣扎一段时间。

这是我的代码,

   $dateBegin = "2010-12-07 15:54:24.0";
$dateEnd = "2010-12-30 18:19:52.0";
$textPerson = " text text  text text  text text  text text  text text  text text  text text "; 



$textPersonExplode = explode(" ", $textPerson );



$db = dbConnect();
for ( $counter = 0;$counter <= sizeof($textPersonExplode)-1 ; $counter++) {


$query = "SELECT count(word) FROM `news_google_split`  WHERE `word` LIKE '$textPersonExplode[$counter]'   AND  `date` >= '$dateBegin' AND `date` <= '$dateEnd'"; 

$result = mysql_query($query) or die(mysql_error());



while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
 $word[] = $textPersonExplode[$counter];
 $count[] = $row[0];



}
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
}

感谢您的帮助。

i want to look how much an array comes in a database. Its pretty slow and i want to know if there's a way of searching like multiple words or an whole array without a for loop.. i'm struggeling for a while now.

here's my code

   $dateBegin = "2010-12-07 15:54:24.0";
$dateEnd = "2010-12-30 18:19:52.0";
$textPerson = " text text  text text  text text  text text  text text  text text  text text "; 



$textPersonExplode = explode(" ", $textPerson );



$db = dbConnect();
for ( $counter = 0;$counter <= sizeof($textPersonExplode)-1 ; $counter++) {


$query = "SELECT count(word) FROM `news_google_split`  WHERE `word` LIKE '$textPersonExplode[$counter]'   AND  `date` >= '$dateBegin' AND `date` <= '$dateEnd'"; 

$result = mysql_query($query) or die(mysql_error());



while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
 $word[] = $textPersonExplode[$counter];
 $count[] = $row[0];



}
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
}

thanks for the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

败给现实 2024-10-18 22:18:23

如果在查询中使用 MATCH..AGAINST 对,则可以避免 for 循环。 IE:

    $query = "SELECT count(word) FROM `news_google_split`  WHERE MATCH(`word`) AGAINST   
('$textPerson')   AND  `date` >= '$dateBegin' AND `date` <= '$dateEnd'"; 

You can avoid the for loop if you use MATCH..AGAINST pair in your query. i.e:

    $query = "SELECT count(word) FROM `news_google_split`  WHERE MATCH(`word`) AGAINST   
('$textPerson')   AND  `date` >= '$dateBegin' AND `date` <= '$dateEnd'"; 
街角迷惘 2024-10-18 22:18:23

我们在 Db 中发送一个逗号分隔的列表,然后将该列表转换为一个表,然后我们在查询中以联接的形式使用该表。

但是,您需要确保可以传入多少数据作为查询或存储过程的输入。

We send a comma seperated list in Db, then converted that list into a table, then we used that table in our queries in the form of joins.

However you need to make sure how much data you can pass in as the input of the query or stored procedure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文