Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8880171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:07:01+00:00 2026-06-14T20:07:01+00:00

I’m using sqlite’s full-text-search support to store documents that may contain & , <

  • 0

I’m using sqlite’s full-text-search support to store documents that may contain &, < and > characters. I intended to use the snippet function to highlight the matches for an html results page, but I don’t see an obvious way to escape the text before injecting the markers. I’d rather not escape the text before storing it, because then amp, lt and gt will become tokens.

The simplest workaround I can think of is to escape the pages before storing them, and use a custom tokenizer that would first unescape &amp;, &lt; and &gt;.

However… since the default for snippet(foo) is to use <b> and </b>, it really seems like this is a very common use case and I’m convinced that there must be a way to handle this without reinventing the wheel in C. Am I overlooking a more elegant solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:07:02+00:00Added an answer on June 14, 2026 at 8:07 pm

    It appears that FTS indeed does not handle markup in text (note how the <p> gets chopped up):

    > CREATE VIRTUAL TABLE test USING fts3(content TEXT);
    > INSERT INTO test VALUES('<p>Isn''t this <font face="Comic Sans">funny</font>?');
    > INSERT INTO test VALUES('blah');
    > SELECT snippet(test) FROM test WHERE content MATCH 'funny';
    p>Isn't this <font face="Comic Sans"><b>funny</b></font>?
    > SELECT snippet(test) FROM test WHERE content MATCH 'font';
    p>Isn't this <<b>font</b> face="Comic Sans">funny</<b>font</b>>?
    

    The cleanest way to store the text is as plain text, unescaped.
    However, to get proper highlighting of search results, you have two choices:

    • Use the optional parameters of snippet to specify markers that are guaranteed to never occur in the text (which might not be possible), and convert those to <b>... when you are escaping the text for HTML; or
    • use the offsets function instead and insert the markers by hand.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.