#C143. Simulate MySQL Full-Text Search
Simulate MySQL Full-Text Search
Simulate MySQL Full-Text Search
You are given a search query and a set of database records, where each record contains a title and content. Your task is to simulate a simplified version of MySQL's full-text search functionality. In this simulation, the search should be case-insensitive and should return only those records that contain all of the query words.
Details:
- If the query string is empty, no records should be returned.
- The search is case-insensitive. This means, for matching the words, you should convert both the query and the record fields to lowercase.
- A record is considered a match only if every word in the query appears somewhere in the record (in either the title or the content).
Example:
For example, given a query Python powerful and records including a record with title "Learn Python" and content "Python is a powerful programming language.", the record is returned because both "Python" and "powerful" are found in the record.
Your solution should read input from standard input and output the result to standard output.
inputFormat
The input is given via stdin with the following format:
- The first line contains a string
query
. - The second line contains an integer
n
representing the number of records. - The next 2*n lines describe the records. For each record, the first line is the
title
and the second line is thecontent
.
For example:
Python 4 Learn Python Python is a powerful programming language. Dive into MySQL MySQL supports full-text search for efficient search capabilities. Effective Java Java is widely used in large scale applications. PHP Development Build dynamic websites using PHP and MySQL.
outputFormat
The output should be printed to stdout and have the following format:
- The first line contains an integer
m
which is the number of records that match the query. - For each matching record, print two lines: the first line is the record's
title
and the second line is itscontent
.
If no records match, output a single line with 0.
## samplePython
4
Learn Python
Python is a powerful programming language.
Dive into MySQL
MySQL supports full-text search for efficient search capabilities.
Effective Java
Java is widely used in large scale applications.
PHP Development
Build dynamic websites using PHP and MySQL.
1
Learn Python
Python is a powerful programming language.
</p>