Find occurrences of huge list of phrases in text : <p>I'm building a backend and trying to crunch the following problem.</p>

<ul>
<li>The clients submit text to the backend (around <code>2000</code> characters on average)</li>
<li>Backend endpoint that receives the request has to apply phrase highlighting to the submitted text</li>
<li><p>There is around <code>80k</code> phrases to match. A phrase is a simple object:</p>

<pre><code>{
    'phrase': 'phrase to match'
    'link': 'link_url'
}
</code></pre></li>
<li><p>After finding all matches of phrases that exist in the text, the backend returns to the client what was matched - basically a map:</p>

<pre><code>range in text -&gt; phrase
</code></pre></li>
</ul>

<p>Most is done. I'm about to tackle coding the phrase matching part. Everything else works smoothly. Since I don't want to reinvent the wheel I tried googling to find a Python library that does the job of efficiently finding phrases (from huge list) in text. However, I couldn't find anything.</p>

<p>I checked out the <a href="https://www.crummy.com/software/BeautifulSoup/" rel="noreferrer">BlueSoup</a> and <a href="https://www.nltk.org/" rel="noreferrer">Natural Language Toolkit</a>. However they don't seem to be doing what I'm looking for.</p>

<p>Do you guys know if there is a library that would be helpful in such task? Seems like a common thing to implement and I don't want to go custom if there is a well established library for that.</p>
