简体   繁体   English

连接字符串的高级搜索

[英]Advanced search in concatenating string

i am creating a search functionality for a website where i need to take the user's full address from an input eg "Address 32, City,Region,Country, Postal Code"(no necessary with this order) and return the available restaurant that are around the area. 我正在为网站创建搜索功能,我需要从输入中获取用户的完整地址,例如“地址32,城市,地区,国家/地区,邮政编码”(此订单不需要)并返回附近的可用餐厅该地区。 I have a table "address" where there is a field for each of the above elements. 我有一个表“ address”,上面的每个元素都有一个字段。 I was thinking of concatenating the users address from the database and compare it with the user's input by help of SQL REGEXP. 我当时正在考虑将数据库中的用户地址连接起来,并借助SQL REGEXP将其与用户输入进行比较。 Is there any other approximate SQL search that can give me that or can you suggest me a different approach? 还有其他近似的SQL搜索可以给我带来这种感觉,还是可以建议我使用其他方法? A friend suggested using ( http://www.simonemms.com/2011/02/08/codeigniter-solr/ ) however with a small research on it the problem still remains. 一位朋友建议使用( http://www.simonemms.com/2011/02/08/codeigniter-solr/ ),但是对它的少量研究仍然存在问题。

Trouble with concatentating the address together in SQL is you will miss out on it using indexes. 在SQL中同时配置地址的麻烦是,您将无法使用索引错过它。 Hence it will be slow. 因此,它将很慢。 Added to which if you do not know the order of the input elements the chances of it matching what is concatenated from the database (is a likely different order) is slim. 另外,如果您不知道输入元素的顺序,则它与数据库中连接的内容匹配的可能性很小(可能是不同的顺序)。

I would suggest for much of the address items, split them off into different tables (ie a table of regions, another of countries, etc) and just store the ids in the columns in the users table. 我建议使用大多数地址项,将它们拆分成不同的表(即,区域表,另一个国家/地区等),然后将ID存储在users表的列中。

For a search, identify which of the search fields go with which actual field then join on those to find the real address. 对于搜索,请确定哪些搜索字段与哪个实际字段一起使用,然后在这些搜索字段上合并以找到真实地址。

Also means you can identify typos more easily. 也意味着您可以更轻松地识别错别字。

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

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