How to implement a Keyword Search in MySQL?

后端 未结 7 1095
温柔的废话
温柔的废话 2020-11-29 20:25

I am new to SQL programming.

I have a table job where the fields are id, position, category, location, sala

7条回答
  •  我在风中等你
    2020-11-29 21:08

    You can find another simpler option in a thread here: Match Against.. with a more detail help in 11.9.2. Boolean Full-Text Searches

    This is just in case someone need a more compact option. This will require to create an Index FULLTEXT in the table, which can be accomplish easily.

    Information on how to create Indexes (MySQL): MySQL FULLTEXT Indexing and Searching

    In the FULLTEXT Index you can have more than one column listed, the result would be an SQL Statement with an index named search:

    SELECT *,MATCH (`column`) AGAINST('+keyword1* +keyword2* +keyword3*') as relevance  FROM `documents`USE INDEX(search) WHERE MATCH (`column`) AGAINST('+keyword1* +keyword2* +keyword3*' IN BOOLEAN MODE) ORDER BY relevance;
    

    I tried with multiple columns, with no luck. Even though multiple columns are allowed in indexes, you still need an index for each column to use with Match/Against Statement.

    Depending in your criterias you can use either options.

提交回复
热议问题