「相关文章」结果是越相关排名越前的案例,求一个高效的写法
我的文章系统,想按照多个件条下
,看看有什么可能性可做到
4张表 基础简介
content 文章主表
id
lid = 相关的文集id ,保存格式 (1,2,3)
tags = 相关的TAG 的ID ,保存格式 (1,2,3)
typeid = 分类ID 只为1个数字
文集
lid
name
Tags
id
name
分类
typeid
name
typeid = 分类ID, 不别多说
tag = 标签这不用多说,
lid = 一个文集, 但一篇文章可以放到多个文集, 比如: PHP+MYSQL+AJAX无刷新评论
用户可能放到 PHP文集,MYSQL文章,AJAX文集
TAG 是全站共用,重复就不新增,只会选择
所以不能做成一个自己文章的分类列表,所以会出现了文集功能
因为文章某个部分已经会显示当前文集其他的文章
所以在关相文章的部分,文集中的文件不比TAG文章更应该排在前面
所以准备的关系排名是
1. TAG相关
2. 文集
3. 最新的当前分类文章
为什么要分3次???
因为我就是怕太TAG,同时又没有用到文集功能....
所以最后一步才是当前分类文章
当前文章的
TAG 是3,14
lid = 7,12
typeid = 2
SELECT * FROM `content` WHERE `tags` IN (3,14) ORDER BY `time` DESC LIMIT 10
SELECT * FROM `content` WHERE `lid` IN (7,12) ORDER BY `time` DESC LIMIT 10
SELECT * FROM `content` WHERE `typeid` = '2' ORDER BY `time` DESC LIMIT 10
前台显示十条相关文章
本来是准备,分3次,然后每次拿10条是最安全的
后来想想...这样还有合并数组什么的也麻烦,重点是取太多资料,但前台只需要10条
所以换成一句
SELECT * FROM `video_content` WHERE `tags` IN (3,14) or `lid` IN (3) or `typeid` = 2 LIMIT 10
但这样好像又能以TAG>文集>分类...去排名
请求一下有何方法?
要求好像蛮麻烦的呵呵,因为页面下半部有50%的部分是显示相关文章,所以在营运上很重要
回复讨论(解决方案)
暂时用了这一段代码,感觉有点蠢
有什么更好的方法建议呢?
//相关文章if (!empty($data["tags"]) || !empty($data["lid"])) { $tags = $data["tags"]; $lid = $data["lid"]; $tag_sql = "SELECT * FROM `content` WHERE `tags` IN ($tags) OR `lid` IN ($lid) ORDER BY `time` DESC LIMIT 8"; $stmt = $pdo->prepare($tag_sql); $stmt->execute(); $tags_v = $stmt->fetchAll(PDO::FETCH_ASSOC); $smarty -> assign("r_v",$tags_v);}$tags_num = count($tags_v);if ($tags_num < 8 ) { $now_v = ""; foreach ($tags_v as $key => $value) { $now_v .= $value['vid'].","; } $now_v=substr("$now_v",0,-1); $need = 8-$tags_num; $typeid = $data["typeid"]; $typeid_sql = "SELECT * FROM `content` WHERE `typeid` = '$typeid' AND `vid` NOT IN ($now_v) ORDER BY `time` DESC LIMIT $need"; $stmt = $pdo->prepare($typeid_sql); $stmt->execute(); $typeid_v = $stmt->fetchAll(PDO::FETCH_ASSOC); $smarty -> assign("r_tv",$typeid_v);}
sql用or、not in本来就不好;
如果数据不需要太及时的话
把你3条sql语句组合好的数据缓存一段时间(半小时、一小时、甚至再长一点也可以)
因为你的数据都是死数据,没有浏览量,评论量等等
sql用or、not in本来就不好;
如果数据不需要太及时的话
把你3条sql语句组合好的数据缓存一段时间(半小时、一小时、甚至再长一点也可以)
因为你的数据都是死数据,没有浏览量,评论量等等
这个我也了解
但更想知道的是,如果按照更有关的排得更前
就是先排TAG 再排LID 最后再排同类其他文章
莫非只能用二楼的方法?
你的 意思是不是如果要10条tag,就先取10条tag,不够再取有lib,接着不够再取有type的?
如果是这样的话, 你的sql是不是会有问题!
你的 意思是不是如果要10条tag,就先取10条tag,不够再取有lib,接着不够再取有type的?
如果是这样的话, 你的sql是不是会有问题!
是的
2楼暂时做了个简单的
暂时先不分tag和lid
不够再取type
以及2楼用8条做测试
是否有更好的做法?
用全文检索来做

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The 2024CSRankings National Computer Science Major Rankings have just been released! This year, in the ranking of the best CS universities in the United States, Carnegie Mellon University (CMU) ranks among the best in the country and in the field of CS, while the University of Illinois at Urbana-Champaign (UIUC) has been ranked second for six consecutive years. Georgia Tech ranked third. Then, Stanford University, University of California at San Diego, University of Michigan, and University of Washington tied for fourth place in the world. It is worth noting that MIT's ranking fell and fell out of the top five. CSRankings is a global university ranking project in the field of computer science initiated by Professor Emery Berger of the School of Computer and Information Sciences at the University of Massachusetts Amherst. The ranking is based on objective

1. How can you make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! 1. Activate basic rights and interests: original articles can earn profits by advertising, and videos must be original in horizontal screen mode to earn profits. 2. Activate the rights of 100 fans: if the number of fans reaches 100 fans or above, you can get profits from micro headlines, original Q&A creation and Q&A. 3. Insist on original works: Original works include articles, micro headlines, questions, etc., and are required to be more than 300 words. Please note that if illegally plagiarized works are published as original works, credit points will be deducted, and even any profits will be deducted. 4. Verticality: When writing articles in professional fields, you cannot write articles across fields at will. You will not get appropriate recommendations, you will not be able to achieve the professionalism and refinement of your work, and it will be difficult to attract fans and readers. 5. Activity: high activity,

PHP form processing: form data sorting and ranking In web development, forms are a common user input method. After we collect form data from users, we usually need to process and analyze the data. This article will introduce how to use PHP to sort and rank form data to better display and analyze user-submitted data. 1. Form data sorting When we collect form data submitted by users, we may find that the order of the data does not necessarily meet our requirements. For those that need to be displayed or divided according to specific rules

Introduction to the basic writing and usage of Java callback functions: In Java programming, the callback function is a common programming pattern. Through the callback function, a method can be passed as a parameter to another method, thereby achieving indirect call of the method. The use of callback functions is very common in scenarios such as event-driven, asynchronous programming and interface implementation. This article will introduce the basic writing and usage of Java callback functions, and provide specific code examples. 1. Definition of callback function A callback function is a special function that can be used as a parameter

Detailed explanation of how to write the less than sign in MyBatis MyBatis is an excellent persistence layer framework that is widely used in Java development. In the process of using MyBatis for database operations, we often use the less than sign (

USDT (Tether) is a cryptocurrency anchored to legal tender, with a ratio of 1:1 to the US dollar. As one of the most popular stablecoins, USDT is widely used in cryptocurrency transactions around the world. For users interested in buying or trading USDT, it is crucial to choose a reliable and secure trading platform. The following is a ranking of the top ten USDT trading platform software apps to help you choose the platform that best suits you. 1. Binance Binance is one of the largest cryptocurrency trading platforms in the world, with a wide user base and diverse trading varieties. As a popular USDT trading platform, Binance provides a variety of trading tools and features designed to ensure users’ trading safety and convenience. 2. HuobiG

The ranking and comparison functions of Vue statistical charts are implemented in the field of data visualization. Statistical charts are an intuitive and clear way to display data. As a popular front-end framework, Vue provides a wealth of tools and components to implement various charts. This article will introduce how to use Vue to implement the ranking and comparison functions of statistical charts. Before starting, we need to install Vue and related chart libraries. We will use Chart.js as the charting library, which provides rich chart types and interactive functions. C can be installed via the following command

Exclusive reveal! The latest ranking of Snapdragon processors With the rapid development of mobile devices such as smartphones, processors, as the core chips of mobile devices, are also constantly evolving and upgrading. As one of the most popular processors on the market, Qualcomm’s Snapdragon processors have attracted much attention. Snapdragon processors have always occupied a place in the mobile device processor market with their excellent performance, power consumption control and high integration. So, among the many Snapdragon processors, which one is the best? This article will reveal the secrets of Snapdragon processor for you
