Hello dear users. I have a small request for you: Can you please tell me how to make hash tags on my website like on Twitter or VK?
2 answers
When a publication is added (or edited), search for tags in its text. The simplest (but not always suitable) tool is regular regular expressions, searching for something in the spirit of /#(\w+)/
.
Finding tags write down the identifier of the publication in which they were found. As a result, if you present in the form of a table, you will have something in the spirit of:
+---------------+------------------------------------+ | Тег | ID публикаций | +---------------+------------------------------------+ | теги | 167956, 165489, 148204 | | хэш | 167956, 147666 | +---------------+------------------------------------+
(For example, two real tags and several records with them from HashCode were taken).
In the case of relational databases, this can be represented, for example, by a table of the form:
+---------------+-------------+ | tagname | post_id | +---------------+-------------+ | теги | 167956 | | хэш | 167956 | | теги | 165489 | ...............................
When you need to search by tag or their intersection, simple work with sets is enough. Choose a set of identifiers for all records that contain (or do not contain) the necessary tags, and output these publications.
- the response lacks information, how to convert the resulting tags into search links or something similar in the publication itself - Specter
I’ll add a little @drdaeman to the answer.
Well, about the conversion, it is still simple here!
If in the text @drdaeman wrote
The simplest (but not always suitable) tool is regular regular expressions, searching for something in the spirit of / # (\ w +) /.
Look for them in the text and highlight. (How to highlight, but somehow, how the soul will fall.)
Well, the search links are processed in the same way as regular tags, but probably just at a different address.
We found a hashtag # lab he will have a link of about this content
<a href = "/ hashtag / # laboratory"> # laboratory <\ a>
Well, at the address / hashtag / we process the resulting hashtag.
ps
You can see how it is done on HASHKODE
<а rel="nofollow" href="/users/2694/drdaeman"> @drdaeman <\a>
LIKE
? For fts? Why do you recommend this? All normal people build indexes and get their search forO(1)
. - drdaeman Nov.