简体   繁体   English

如何在postgresql中存储和搜索带连字符/非连字符的url名称?

[英]How can I store and search for hyphenated/non-hyphenated url names in postgresql?

Lets say I have a forum and I have a thread topic called "Game of Thrones"; 让我们说我有一个论坛,我有一个名为“权力的游戏”的主题; and its stored just that way in the database. 并将其存储在数据库中。 When someone wants to access it, the URL will look like: www.someforum.com/topics/game-of-thrones. 当有人想要访问它时,URL将如下所示:www.someforum.com/topics/game-of-thrones。

When searching, I can simply replace the hyphens with spaces, or ignore them, but it would create ambiguity between different permutations of words and hyphens for strings that have a both spaces and hyphens(eg"Mother-In-Law Issues"). 在搜索时,我可以简单地用空格替换连字符,或者忽略它们,但是对于具有空格和连字符的字符串(例如“婆婆问题”),它会在单词和连字符的不同排列之间产生歧义。 How can I handle this? 我怎么处理这个?

I thought of creating a "slug" column in the topic table which would contain the url for the topic title, and the "title" column would save the permutation of spaces and hyphens as intended by the user... 我想在主题表中创建一个“slug”列,其中包含主题标题的url,“title”列将保存用户预期的空格和连字符的排列...

I think I got you now. 我想我现在找到了你。
How about something like this (just a rough demo)? 这样的事情怎么样(只是一个粗略的演示)? - -

create table url (url_id int primary key,url varchar(1000));
insert into  url (url_id,url) values (1,'www.someforum.com/topics/game-of-thrones');

create table search_term (search_term varchar(1000),url_id int references url(url_id));
insert into search_term values ('game of thrones',1),('GOT',1)

select  u.url

from            search_term     as st

        join    url             as u

        on      u.url_id        =
                st.url_id

where   st.search_term = 'GOT'
;

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

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