当前位置:网站首页>Search engine realizes keyword highlighting
Search engine realizes keyword highlighting
2022-07-27 00:43:00 【Mr_ Joer】
Our idea to realize keyword highlighting is to use html sentence . About to use keywords html The sentences are wrapped up , The commonly used sentences are <span style="font-weght:bold"></span>、<span style="color:xxx"></span>, among xxx You can put English names of common colors (white), Or hexadecimal color code (#ffffff).
Query and get data sets data The code for is as follows :

here data The data structure in is as follows :

You can see the queried data ( Far right ) It is encapsulated into one by one Message object , Splice into a list list, Finally put in QuerySet Data sets data in .
Now let's put every piece of data title、info Keywords in the field are html The parcel , Think of the replace function ( Replace the specified string ); Again because Django On safety grounds , The default output is html Statement does not take effect , You use django.utils.safestring Under the make_safe Method , The code is as follows :
for j in range(0,keyCount):
dict['list'+str(i)].title = mark_safe(dict['list'+str(i)].title.replace(key[j],'<span style="color:red;">%s</span>'%key[j]))
dict['list'+str(i)].info = mark_safe(dict['list'+str(i)].info.replace(key[j],'<span style="color:red;">%s</span>'%key[j]))among dict['list'+str(i)] Yes, I will Paginator The data after paging is encapsulated into a dictionary , The values in key value pairs are one by one Message class ;key[j] Is the current keyword , adopt keyCount Cycle twice to add all keywords before and after html Code , The final visual effect is as follows :

边栏推荐
- 我的第一篇博客-迷茫的大三人
- MySQL associative table queries (reducing the number of queries)
- 【4.2 约数】
- Crop TIF image
- 2022_ SummerBlog_ 008
- Find method of web page parsing by crawler
- Arcgis和Cass实现断面展高程点
- Comparative simulation of LEACH protocol performance, including the number of dead nodes, data transmission, network energy consumption, the number of cluster heads and load balance
- Shufflenet series (2): explanation of shufflenet V2 theory
- V-viewer use
猜你喜欢
![[4.10 detailed explanation of game theory]](/img/df/690f9fb3adcb00317eb3438a76baaa.png)
[4.10 detailed explanation of game theory]

JSCORE day_05(7.6)

JSCORE day_02(7.1)

10_评价分类结果(Evaluate classification)

Matlab based medical imaging technology filtering backprojection simulation, including direct backprojection, S-L filtering, R-L filtering, LeWitt filtering

6_ Gradient descent method
![[interview: concurrent Article 16: multithreading: detailed explanation of wait/notify] principle and wrong usage (false wake-up, etc.)](/img/23/7af903e73e8990459f276b713beec9.png)
[interview: concurrent Article 16: multithreading: detailed explanation of wait/notify] principle and wrong usage (false wake-up, etc.)

Based on the theoretical principle and simulation results of MATLAB spherical decoding, compare 2norm spherical decoding, infinite norm spherical decoding, ML detection

8_多项式回归及模型泛化(Polynomial Regression and Model Generalization)

CDs simulation of minimum dominating set based on MATLAB
随机推荐
【3. 基础搜索与图论初识】
DOM day_ 04 (7.12) BOM, open new page (delayed opening), address bar operation, browser information reading, historical operation
Configure deeplobcut 1 with your head covered
2020-12-20 九九乘法表
Huffman encoding and decoding
2022_ SummerBlog_ 008
Two or three things about redis
并行MPI程序传递发送消息
[4.2 approximations]
【4.7 高斯消元详解】
C语言 关机小程序
Matlab based medical imaging technology filtering backprojection simulation, including direct backprojection, S-L filtering, R-L filtering, LeWitt filtering
【4.9 容斥原理详解】
Three tier architecture simulation
Web middleware log analysis script 2.0 (shell script)
DOM day_02(7.8)网页制作流程、图片src属性、轮播图、自定义属性、标签栏、输入框事件、勾选操作、访问器语法
Complete review of parsing web pages
CSDN article syntax rules
[qt] solve the problem of Chinese garbled code
Class and object notes I
https://wenku.baidu.com/view/06013ca6bad528ea81c758f5f61fb7360b4c2b3c.html