dsh8009271 2015-04-17 09:37
浏览 123

如何根据SQL中的caracters相似度比较字符串?

I'm working on redirecting people if they type a "not really wrong url".

For example I have a good URL http://www.website.com/category/foo-bar-if-bar-foo/. This one works so if a user enter to my website with it, I can retrieve the article corresponding.

But if someone enter to my website with a not really wrong url like http://www.website.com/category/foo-bar-foo/ because an another website has referenced a wrong url, I should redirect him to the right one instead of having a 404 status code...

So how should I do this? and Most important, should I do this ?

I actually use Eloquent with Laravel 4.2.

Thank you in advance.

EDIT

I was wrong about stackoverflow, thanks for your comment. It uses the unique ID of a post.

EDIT 2

I Looked at SOUNDEX function in SQL, it's really good if there is a small difference like a character or two missing. But if my url is as broken as my example, it's not working anymore obviously. But thanks it's gonna be usefull.

  • 写回答

1条回答 默认 最新

  • doumiang2297 2015-04-17 09:43
    关注

    Just thinking off the top of my head, you could create a SQL table (with Full-Text indexing enabled) containing all your paths (it might already exist).

    In the event that a 404 is triggered, hijack that and do a MATCH (Full Text Search) and return the path with the highest scoring MATCH (you can also consider using a score threshold to prevent nonsensical matches).

    评论

报告相同问题?

悬赏问题

  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False