MySQL sort by number of occurrences

前端 未结 3 1471
遥遥无期
遥遥无期 2021-02-09 15:28

I am doing a search in two text fields called Subject and Text for a specific keyword. To do this I use the LIKE statement. I have encount

3条回答
  •  忘了有多久
    2021-02-09 15:45

    // escape $keyword for mysql
    $keyword = strtolower('Keyword');
    // now build the query
    $query = <<

    Returns number of occurrences in each field and sorts by that.

    The 'keyword' needs to be lower cased for this to work. I don't think it's really fast, performance wise as it needs to lower-case fields and there's no case-insensitive search in MySQL afaik.

    You could index each news item (subject and text) by words and store in another table with news_id and occurrence count and then match against that.

提交回复
热议问题