Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sql-queries-9/keyword-search-sql/full-text-search-mysql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE Course ADD FULLTEXT(name, textbook);

SELECT id, name, textbook, credits
FROM Course
WHERE MATCH(name, textbook) AGAINST('Operating Systems');

13 changes: 13 additions & 0 deletions sql-queries-9/keyword-search-sql/full-text-search-postgresql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Add a tsvector column for full-text search
ALTER TABLE Course ADD COLUMN search_vector tsvector;

-- Populate the tsvector column with data from the 'name' and 'textbook' columns
UPDATE Course SET search_vector =
to_tsvector('english', name || ' ' || textbook);

-- Create a GIN index on the search_vector column for faster querying
CREATE INDEX idx_course_search ON Course USING GIN (search_vector);

SELECT id, name, textbook, credits
FROM Course
WHERE search_vector @@ to_tsquery('Operating & Systems');
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE FULLTEXT CATALOG ftCatalog AS DEFAULT;
CREATE FULLTEXT INDEX ON Course(name, textbook) KEY INDEX PK_Course;

SELECT id, name, textbook, credits
FROM Course
WHERE CONTAINS((name, textbook), 'Operating AND Systems');
7 changes: 7 additions & 0 deletions sql-queries-9/keyword-search-sql/using-like-operator.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT id, name, textbook, credits
FROM Course
WHERE name LIKE '%Operating%';

SELECT id, name, textbook, credits
FROM Course
WHERE name LIKE '%Database Systems%' OR textbook LIKE '%Database Systems%';