在易優搜索中,默認情況下是從文章標題中進行搜索。這是因為數據庫中存儲的標題內容是純文本,所以無需進行過濾。然而,在某些情況下,我們需要從文章內容中全站搜索并檢索關鍵詞,而默認的搜索功能顯得不夠靈活。但是,通過靈活運用SQL語句,我們可以直接實現這一功能。具體方法如下:
{eyou:sql sql="select aid from ey_article_content where content like '%$keywords%' union select aid from ey_archives where title like '%$keywords%' union select aid from ey_product_content where content like '%$keywords%' limit 0,5" } {eyou:sql sql="select aid from ey_archives where aid='$aid'" id="field3"} <li class="dot"> {eyou:arcview aid="$field3.aid" id="field2" addfields="content" } <a href="{$field2.arcurl}" title="{$field2.title}"><h1>{$keywords,"<font color='red'>$keywords</font>",$field2.title|str_replace}</h1></a> {eyou:assign name="neirong" value="$field2.content|html_msubstr"} <div>{$neirong,$keywords|diy_content}</div> <span>{$field2.add_time|MyDate='Y-m-d',###}</span> </li> {/eyou:arcview} {/eyou:sql} {/eyou:sql}
然而,需要注意的是,易優數據庫中的content
字段存儲的是帶有HTML標簽的內容。如果搜索的關鍵字包含常見的HTML標簽(如"a"、"p"、"br"等),會導致搜索結果顯示全部文章。盡管這種方法勉強可行,但可能會影響搜索結果的準確性。因此,建議對搜索關鍵字進行過濾或限制,以避免這個問題。
綜上所述,通過使用SQL語句和適當的關鍵字過濾,我們可以實現從文章內容中搜索關鍵字的全站搜索功能。希望這個解決方法對你有所幫助。