简体   繁体   English

处理搜索参数 URL PHP

[英]Handling search parameters URL PHP

I am wondering if I would be able to get some advice.我想知道我是否能够得到一些建议。

I am trying to build a search for my site and I want to link to be reusable so it can be sent as a link to someone else to see the same results.我正在尝试为我的网站构建搜索,并且我希望链接可重用,以便可以将其作为链接发送给其他人以查看相同的结果。

The problem I have is that there is the possibility to have 100s of parameters for this search, so I dont think a GET requests in the URL are the right way to go.我遇到的问题是这个搜索有可能有 100 个参数,所以我不认为 URL 中的 GET 请求是 go 的正确方法。

I was thinking of the possibility of creating a JSON file that saves the parameters in the search and to give it a specific name say "qwer-eweq-qwe" then the URL link could be www.mysite.com/qwer-eweq-qwe我正在考虑创建一个 JSON 文件的可能性,该文件在搜索中保存参数并给它一个特定的名称说“qwer-eweq-qwe”,然后 URL 链接可能是www.mysite.com/qwer-eweq-qwe

Then once a user would navigate to the URL it would then read the JSON file and pull the correct parameters.然后,一旦用户导航到 URL,它就会读取 JSON 文件并提取正确的参数。

Is there any other ways I could do this?我还有其他方法可以做到这一点吗? Can seem to find too much online.好像网上找的太多了。 any pointers would be very helpful任何指示都会非常有帮助

Thanks,谢谢,

Richard理查德

With so many parameters, please, consider switching way of dealing with it.有这么多参数,请考虑切换处理方式。

An idea would be to use a filter system.一个想法是使用过滤系统。 One POST method would create a filter with a set of parameters in body (either raw or JSON, does not matter).一种 POST 方法会在 body 中创建一个带有一组参数的过滤器(raw 或 JSON,没关系)。

POST /filter

The call would create (or not, if already exists) a filter.该调用将创建(或不创建,如果已经存在)过滤器。 The call would return a filter ID that you can use to search by fixed parameters:该调用将返回一个过滤器 ID,您可以使用它按固定参数进行搜索:

GET /search/:filterid

That way, you even can manage cache limitations depending on filters, by invalidating those if needed.这样,您甚至可以根据过滤器来管理缓存限制,如果需要,可以使它们失效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM