Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server and regular expressions

Which will be better among following option ?

  1. Regular-expressions in SQL Server searches, as new versions support CLR objects ?
  2. Full text search ?
  3. Lucene.net combined with SQL Server ?

Our database will be having millions and millions of records and we will be providing Google-like search option, and like Google searches for anything, we will be searching some specific categories only.

Please help.

like image 724
pokrate Avatar asked Feb 27 '10 19:02

pokrate


People also ask

What are SQL regular expressions?

Regex, or Regular Expressions, is a sequence of characters, used to search and locate specific sequences of characters that match a pattern.

Why regex is used in SQL?

REGEXP is the operator used when performing regular expression pattern matches. RLIKE is the synonym. It also supports a number of metacharacters which allow more flexibility and control when performing pattern matching. The backslash is used as an escape character.

Can you use regex in SSMS?

You can specify precise and complex expressions using regex to find and replace various strings and patterns. In tools, such as SSMS, you can specify the regex patterns in the Find What and Find and Replace options.


2 Answers

  1. Regular Expressions are fine as long as your data is small, very small.

  2. Full text Search with SQL is good choice. I do not personally do not like this option because the search syntax isn't as expressive as Lucene.Net. But either way it is a good way to quickly get some full text search going, without going into a lot of details.

  3. Lucene.Net gives your more control/responsibility of creating and maintaining the index, so if this doesn't scare you away then Lucene.Net gives your high quality results and you can do a lot with it. You can customize and tweak just about everything to get your search engine working the way you want it to work. I would personally choose Lucene.Net.

In sort.

  1. don't use regular expressions.
  2. SQL Server Full Text Search is a quick and easy way to get a decent search out of it, without being to technical.
  3. Lucene.Net is the best for it's quality of results, but requires you to go through some learning (if your new).
like image 158
Andrew Smith Avatar answered Sep 23 '22 15:09

Andrew Smith


For searching large amounts of data, you want a full text index. Regular expressions are more flexible and can provide more power to your users to express their queries, but it will be slower.

Lucene is a fine choice, but you might find that the built-in features that SQL Server has already meet your needs.

like image 39
Mark Byers Avatar answered Sep 24 '22 15:09

Mark Byers