简体   繁体   中英

should I implement my search engine string parser on client or server?

I have an html input that sends the query string through an ajax call to my php server. The search string can be complex and allow for filters, my implementation question looking for feedback is should I handle the parsing of the fields/values on the client side and dynamically add post values or should I handle everything on the server side?

Example: From the search box you could enter things such as

'search string category:sports submitted:today'

Then I could either

javascript submits

(POST) q='search string category:sports submitted:today' 

server parses to

query='search string' 
category='sports' 
submitted'today' 

OR

javascript parses and submits

(POST) q='search string'
(POST) category='sports'
(POST) submitted='today' 

server handles post parameters

query='search string' 
category='sports' 
submitted='today' 

我会选择方式1,因为服务器和客户端之间的交互最小。

Depends on how interactive you want your application to be.

IF the client parses it while the user is typing, you could provide auto-fill features and validation. Else you have to wait for the user to be done and then receive feedback from the server.

Technically it is not a big deal for the server-side to parse. But it just may not be the optimum application behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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