How is the database searched?

I am trying to make a search function on my site:
Unfortunately, I do not know how?

is LIKE enough for the search function? eg:

SELECT * FROM Employees WHERE (Title Like 'Title%') 

or are there more professional ways? (e.g. regular expressions)

+4
source share
5 answers

There are several approaches that you could use if you want to implement a system to perform adhoc searches on your relational data:

  • Use an open source search engine like Lucene
  • Use the text indexing functionality of your database — if there is one — it depends on the database you are using. Information for: Oracle / SQL Server / MySQL / PostgreSQL
  • Write your own search engine using an inverted pointer - although this is a bit pointless if you can use option 1 or 2.
+6
source

If you ask how to implement the search capabilities on your website (for example, the search box at the top of each / some pages / pages), it depends on the implementation of your website.

  • If you use a database repository to store the entire contents of a site, you can use it to search the database. But search by content / headings / etc. or use full-text search.
  • If you use any CMS / portal solution, it probably already supports search capabilities.
  • If you use static content, you will have to execute it through a file search.
+1
source

With relational databases, you are pretty much left with a search-string (LIKE), which may not be flexible enough, and also works (efficiently) with short columns (like a heading).

Thus, you probably need to use a full-text search engine (e.g. Lucene). In this case, a full-text search index outside the database will be used to search for keywords.

Some relational databases have optional full-text search capabilities for their text columns. Using them, you can send your full-text queries using SQL (and even combine it with queries on other columns). In Oracle, it looks like

 SELECT id FROM table WHERE CONTAINS(text_column, 'java AND text', 1) > 0; 
+1
source

You might want to explore a full-text search engine such as Lucene .

Lucene is stand-alone software that indexes everything you say to index (for example, some of the objects in the database). When performing a search, you first use the Lucene API to search for a full-text index and obtain a set of object identifiers. Then you perform an easy database retrieval to get objects with these identifiers.

0
source

LIKE is perfect

-1
source

All Articles