2012-05-14 19 views
0

検索されたフィールドの検索キーワードの繰り返しを数える必要があります。例えばmysqlによる検索キーワードの検索検索機能との関連性の問い合わせ

、私はこの

ID  post _content  post_title 
----------------------------------------------- 
    1  page page page  page 
    2  page test   page 
    3  page foo   test 

のようなテーブルwp_postsを持っている場合、私はページ

ID total count 
1 4 
1 2 
2 1 
+0

をしようとした場合のようになりたいです2つのテーブルか、ただ1つ...?または訪問の回数を格納する場所はどこですか? – Addicted

答えて

1

のためのいずれかの検索はあなたが持っているんこの

SELECT id , 
       FLOOR(((length(REPLACE(post_content, '', '')) 
         - length(REPLACE(REPLACE(post_content, ' ', ''), 
             'page', ''))))/length('page')) 
       + FLOOR(((length(REPLACE(post_title, ' ', '')) 
          - length(REPLACE(REPLACE(post_title, ' 
', ''), 'page', ''))))/length('page')) "count of 'page'" 
     FROM page_search ; 
+0

これは動作しているようです – Obhaso