MySQL搜索结果 - 按相关性排序(MySQL Search Result - Sort by Relavance)
我正在尝试编码搜索网站数据库的基本搜索引擎的相关功能。 让我们以Yelp为例。 ( 直接链接到页面 http://www.yelp.com/search?find_desc=chinese&ns=1&find_loc=New+York%2C+NY )
问题1
他们如何确定“最佳匹配”? 我猜他们会搜索包含关键字的所有条目至少一次,然后按关键字出现在标题/标记/说明中的次数进行排序。
问题2
对于“最高评分”和“最多评论”排序,他们搜索包含关键字的所有条目,然后分别按平均评分和评论数排序。
问题3
我使用CodeIgniter和MySQL和Active Records。 比方说,我的表“产品”有列'ID,名称,类别,标签,说明'。
- 如何执行一个查询,该查询返回出现在其中一列中的关键字的所有行
- 我如何计算关键字出现在MySQL查询的这些列之一中的次数。
I am trying to code the relevency features of a basic search engine that searches the database of a website. Lets take the example of Yelp. (Direct link to page http://www.yelp.com/search?find_desc=chinese&ns=1&find_loc=New+York%2C+NY)
Question 1
How do they determine a 'Best Match'? I'm guessing they search for all entries containing the keyword at least once, then sort by the number of times the keyword appears in the title/tag/description.
Question 2
For sorting by 'Highest Rated' and 'Most Reviewed', they search for all entries containing the keyword, then sort by average ratings and number of reviews respectively.
Question 3
I'm using CodeIgniter with MySQL and Active Records. Lets say my table 'products' has the columns 'id, name, categories, tags, description'.
- How do I do a query that returns all rows with the keyword appearing in one of these columns, and
- how do I count count the number of times the keyword appear in one of these columns in the MySQL query.
原文:https://stackoverflow.com/questions/5943596
最满意答案
试试:
<?php if(!empty($bids)) { $debitSum = 0; $creditSum = 0; foreach ($bids as $bid) { $debit = $bid['Bid']['debit']; $credit = $bid['Bid']['credit']; echo '<tr>'; echo '<td>' . ( $debit > 0 ? $debit : ' ' ) . '</td>'; echo '<td>' . ( $credit> 0 ? $credit : ' ' ) . '</td>'; echo '</tr>'; $debitSum += $debit; $creditSum += $credit; } echo '<tr style="font-weight: bold">'; echo '<td>' . $debitSum . '</td>'; echo '<td>' . $creditSum . '</td>'; echo '</tr>'; } ?>
编辑:
如果
$bid['Bid']['debit']
(或信用额度)是字符串值,则将其转换为int值:$debit = (int) $bid['Bid']['debit'];
Try with:
<?php if(!empty($bids)) { $debitSum = 0; $creditSum = 0; foreach ($bids as $bid) { $debit = $bid['Bid']['debit']; $credit = $bid['Bid']['credit']; echo '<tr>'; echo '<td>' . ( $debit > 0 ? $debit : ' ' ) . '</td>'; echo '<td>' . ( $credit> 0 ? $credit : ' ' ) . '</td>'; echo '</tr>'; $debitSum += $debit; $creditSum += $credit; } echo '<tr style="font-weight: bold">'; echo '<td>' . $debitSum . '</td>'; echo '<td>' . $creditSum . '</td>'; echo '</tr>'; } ?>
Edit:
If
$bid['Bid']['debit']
(or credit too) is a string value, then cast it to int value:$debit = (int) $bid['Bid']['debit'];
相关问答
更多-
使用array_fill根据需要用尽可能多的项填充数组(因为它们都是相同的)然后将它们打印出来。 $v) {?>来自OP的评论如下, 我不需要匹配的$ arr的ID,我需要$ arr的每个键。 我只是想基于我的$ numbers var在$ array中提取某些数组。 如果你想根据$numbers ids从$array提取匹配的内部数组 ,解决方案将是这样的: $numberIds = explode(',', $numbers); $resultArr = array(); foreach($array as $arr){ if(in_array($arr['id'], $numberIds)){ ...试试: '; echo '
' . ( $debit > 0 ? $debit : ' ' ) . ' '; ...我想要的是它应该使用的URL中没有product_cat 只需将您的单词转换为基本if条件,例如: if ($_GET['product_cat'] == $cat): ?>