I've been considering how to best optimize friendly URLs, or something like "/mysql-and-friendly-urls/" instead of "/forums/showthread.php?p=949152". This system is opposed to having a simple query match for the relative URL.
DB Structure
TABLE: words
w char(9) - the word, limited to 9 characters, primary index
k smallInt - the 'key', an integer used to reference to the word
c tinyInt - count, how many resources this word points to
ex.
w | k | c
'this' | 115 | 112
'is' | 28 | 496
'a' | 31 | 337
'title' | 5049 | 8
TABLE: switch
i mediumInt - an id, primary index, no use other than being required by MySQL
k smallInt - a key from the words table, normal index
r mediumInt - resource ID
i | k | r
1029 | 115 | 6089
1030 | 115 | 4356
1031 | 115 | 87652
TABLE: rels
r mediumInt - resource ID
... - data used to reference to where and how the content is stored
---------
Handling
- URL is forwarded to PHP file
- Stripped of unsafe characters
- Exploded by "-"
- Words with lengths greater than 9 are stripped ( by MySQL probably )
- Query applied*
- If multiple resources are found, they are returned in list form with an additional "+IDOFRESOURCE" at end of URI.
- Otherwise, data delivered
*The Query
The query needs work. I'd like to expand it to grab the $keys as it goes, and have a limit based upon the lowest count found, but I'm not quite sure on how to do this i MySQL effectively.
Any input would be appreciated.
DB Structure
TABLE: words
w char(9) - the word, limited to 9 characters, primary index
k smallInt - the 'key', an integer used to reference to the word
c tinyInt - count, how many resources this word points to
ex.
w | k | c
'this' | 115 | 112
'is' | 28 | 496
'a' | 31 | 337
'title' | 5049 | 8
TABLE: switch
i mediumInt - an id, primary index, no use other than being required by MySQL
k smallInt - a key from the words table, normal index
r mediumInt - resource ID
i | k | r
1029 | 115 | 6089
1030 | 115 | 4356
1031 | 115 | 87652
TABLE: rels
r mediumInt - resource ID
... - data used to reference to where and how the content is stored
---------
Handling
- URL is forwarded to PHP file
- Stripped of unsafe characters
- Exploded by "-"
- Words with lengths greater than 9 are stripped ( by MySQL probably )
- Query applied*
- If multiple resources are found, they are returned in list form with an additional "+IDOFRESOURCE" at end of URI.
- Otherwise, data delivered
*The Query
Code:
select *
from resources l
where exists (
select 2
from switch s
where
s.k in ('.implode(',',$keys).')
)
Any input would be appreciated.