2005/05/29
plone の検索ボックスからまとめて検索
作成者 takanori
—
投稿日
2005年05月29日 12時10分
最終変更日時
2006年04月05日 00時48分
plone の画面の右上に表示されている検索ボックスで検索を実行すると、当然ですが plone サイトの中にあるアイテムが検索結果として表示されます。
Plonified スキンを使用すると、ユーザから COREBlog のエントリーはあたかも plone のアイテムのように見えますが、検索結果としては出てきません。でも、COREBlog 自体は検索にもちゃんと対応しています。
というわけで、検索ボックスに文字列を入力すると、COREBlog からの検索結果も表示されるようにしてみました。
検索結果は こんな風に 表示されます。
んで、やり方です。
plone サイトの portal_skins/plone_forms にアクセスして、
search というアイテムをカスタマイズ用にコピーします。
あとは、一番最後の </div> の前に以下のコードを入れます。
一番最初の blog python:here.takalog の部分はみなさんの環境に合わせて書き換えてください。:
<div tal:define="blog python:here.takalog;
blogurl blog/absolute_url;
bresults python:blog.searchResults(search_text=request.SearchableText)">
<h1>COREBlog からの検索結果</h1>
<div tal:condition="not: bresults">
<p><strong i18n:translate="description_no_results_found">No results were found.</strong></p>
</div>
<div tal:condition="bresults">
<strong>
<span i18n:translate="batch_x_items_matching_your_criteria"><span i18n:name="number" tal:content="python:len(bresults)">234</span> items matching your criteria.</span>
</strong>
<dl>
<tal:results tal:repeat="result bresults">
<tal:entry tal:define="entry python:blog.get_entry(result.id);
result_url result/getURL;
url string:$result_url?searchterm=${searchterm};">
<dt>
<a
href="#" tal:attributes="href url"
tal:content="entry/title" />
<span class="discreet"
title="Relevance"
tal:condition="result/data_record_normalized_score_"
i18n:translate="label_relevance_percentage"
i18n:attributes="title">
[<span tal:replace="result/data_record_normalized_score_"
i18n:name="percentage">23%</span>%]
</span>
<span class="discreet" i18n:translate="results_by_author">
by <span tal:replace="entry/author" i18n:name="author">Author</span>,
<span tal:replace="python:here.toPortalTime(DateTime(entry.created), long_format=1)" i18n:name="date">Created</span>
</span>
</dt>
<dd>
<span tal:replace="entry/excerpt">excerpt</span>
</dd>
</tal:entry>
</tal:results>
</div>
</div>
上記のコードだと検索にひっかかった数がやたら多い場合にも「前のページ/次のページ」とかが出ないので、そこは直す必要があるかなーという気がしますが、とりあえずこんな感じで。
あと、ポイントとしては description がないので代わりに excerpt を出力するようにしたので、ちょっと「長い」と感じるかもしれません。
-
- ¦
- 固定リンク
- ¦
- コメント (2)
- ¦
- トラックバック (0)
- トラックバック用URL:
- http://takanory.net/takalog/218/tbping
串刺し検索のやり方がわからなくて、困っていたところです。助かりました。
早速使わせていただきます。
お役に立ててよかったです。どぞどぞ。
でも、まとめてスコア順に表示とかされないのは現状ではいまいちかなーと思ったり。
だったら google さんとかにサイト指定して検索してもらった方が楽ですしねぇ。