用split实现多关键字的搜索

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
  1. <HTML> 
  2. <HEAD> 
  3. <TITLE>用split实现多关键字的搜索</TITLE> 
  4. <style type="text/css"> 
  5. BODY { 
  6. SCROLLBAR-FACE-COLOR: #293863; 
  7. FONT-SIZE: 9pt; 
  8. SCROLLBAR-HIGHLIGHT-COLOR: #e4eaf1; 
  9. SCROLLBAR-SHADOW-COLOR: #000000; 
  10. SCROLLBAR-3DLIGHT-COLOR: #293863; 
  11. SCROLLBAR-ARROW-COLOR: #000000; 
  12. SCROLLBAR-TRACK-COLOR: #e4e4e4; 
  13. SCROLLBAR-DARKSHADOW-COLOR: #293863 
  14. </style> 
  15. </HEAD> 
  16. <BODY> 
  17. <
  18. if request.querystring("action") = "search" then '判断接收到的action值是否为search,如果是的,则开始搜索 
  19. dim strsql 
  20. dim strconn 
  21. dim objrs 
  22. dim strkeyword 
  23. '定义数据库链接串 
  24. strconn = "provider=microsoft.jet.oledb.4.0;data source="&server.mappath("**.mdb") 
  25. set objconn = server.createobject("adodb.connection") 
  26. objconn.open strconn 
  27. strkeyword = request.form("keyword") '取得表单中的关键字 
  28. keywords=Split(strkeyword,"|") '开始提取并键字 
  29. i=0 
  30. strsql="select * from 这里填写字段名 where" 
  31. for each key in keywords 
  32. strsqlstrsql=strsql+" or title like '%"&keywords(i)&"%'" 
  33. ii=i+1 
  34. next 
  35. strsql=Replace(strsql, "where or", "where") '把SQL语句里的where or 替换成where 
  36. set objrs = server.createobject("adodb.recordset") 
  37. objrs.open strsql, objconn,1,3 
  38. if not rs.eof then '判断是否有记录,如果有则循环显示 
  39. while not objrs.eof 
  40. response.write "<b>" &objrs("字段名") &"</b><br>" '这里要改成想要显示的字段 
  41. objrs.movenext 
  42. wend 
  43. else '如果指针到末尾,则表示没有记录 
  44. response.write "没有记录" 
  45. end if 
  46. end if 
  47. %> 
  48. <form action="ceshi.asp?action=search" method="post"> 
  49. 请输入关键字,如果有多个请用"|"分隔: 
  50. 查找标题含有<input type="text" name="keyword"><input type="submit" value=" GO "> 
  51. </form> 
  52. </BODY> 
  53. </HTML> 
<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
好的,根据您的需求,我可以为您提供一个实现图书搜索功能的Python程序,可以按照多个关键字进行搜索,例如:按作者查找、按书名查找、按索书号查找等。 以下是一个基于Python的图书搜索功能的示例代码: ``` # 导入必要的库 import csv # 定义函数:按照关键字搜索图书 def search_book(keywords): # 读取csv文件中的数据 with open('books.csv', 'r') as f: reader = csv.DictReader(f) # 定义一个列表,用于存储符合条件的图书 books = [] # 遍历csv文件中的每一行数据 for row in reader: # 判断当前行是否符合关键字搜索条件 match = True for keyword in keywords: if keyword not in row.values(): match = False break # 如果符合条件,则将该行数据添加到books列表中 if match: books.append(row) # 返回符合条件的图书列表 return books # 主函数 if __name__ == '__main__': # 用户输入关键字 keywords = input('请输入关键字,多个关键字请用空格分隔:').split() # 搜索图书 results = search_book(keywords) # 输出搜索结果 if len(results) == 0: print('没有找到符合条件的图书!') else: for book in results: print('书名:{},作者:{},ISBN:{}'.format(book['title'], book['author'], book['isbn'])) ``` 以上是一个实现图书搜索功能的Python程序,该程序将从books.csv文件中读取图书数据,并根据用户输入的关键字进行搜索,最后输出符合条件的图书列表。用户可以输入多个关键字,程序会自动匹配符合所有关键字的图书。例如,用户可以输入“Python 编程”来搜索所有书名或作者中包含“Python”和“编程”的图书。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值