doumao6212 2015-06-29 17:55
浏览 45

将通配符包含在Laravel / LAMP应用程序搜索功能中的最佳方法是什么?

Our Laravel web app runs several reports for users with results returned and displayed in DataTables.

Currently, each report has a single parameter and can only take one value.

So we currently have a report called "Users by Token" and for this you have to enter a token name to get all the users who have that token assigned. The query is obviously something like:

SELECT USER from USERTOKEN WHERE TOKEN = '<parameter>'

That's all great and good, but now the users are asking for two separate requirements.

First, they would like to have the ability to provide several values for the token like:

SELECT USER FROM USERTOKEN WHERE TOKEN='AC10.1' OR TOKEN = 'PR10.1' OR TOKEN='HR11.1'  

Second they want the ability to have wildcards like"

SELECT USER FROM USERTOKEN WHERE TOKEN like 'AC10.%'

To combine these two things we just have to do something like:

SELECT USER FROM USERTOKEN WHERE TOKEN like 'AC10.%' OR TOKEN like 'PR10.1' OR TOKEN like 'HR11.1'

So when the users enter a "*" in their query, we'll just replace that with a '%' in the query and so on. The like directive should work for exact matches I think if we don't have a '%' in the query, right?

I can't help it think there's probably a better way to do this. How do larger applications handle this problem? (I realize the dangers of using wildcards when it comes to rows returned).

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图