6
Plone検索機能はplone.app.searchパッケージに実装されています。 sort_on変数に含まれる変数は、search templateの結果のソート順を制御するために使用されます。Ploneで検索結果を並べ替える方法
デフォルトでは、この変数に値が設定されていない場合、Ploneはの関連性を並べ替え順序として使用します。
これを(最も新しいもの)に変更する最も簡単な方法は何ですか?
Plone検索機能はplone.app.searchパッケージに実装されています。 sort_on変数に含まれる変数は、search templateの結果のソート順を制御するために使用されます。Ploneで検索結果を並べ替える方法
デフォルトでは、この変数に値が設定されていない場合、Ploneはの関連性を並べ替え順序として使用します。
これを(最も新しいもの)に変更する最も簡単な方法は何ですか?
新しい並べ替えオプションを設定し、並べ替えが設定されていないときの既定の並べ替えを変更するには、検索ビューをカスタマイズする必要があります。
あなたはまだ、関連性でソートすることができますが、その後filter_query
方法に変更する空でない値を使用する必要がある場合:あなたのサイトにこのビューを登録後
from plone.app.search.browser import _, Search, SortOption
class MyCustomSearch(Search):
def filter_query(self, query):
query = super(MyCustomSearch, self).filter_query(query)
if 'sort_on' not in query:
# explicitly set a sort; if no `sort_on` is present, the catalog sorts by relevance
query['sort_on'] = 'EffectiveDate'
query['sort_order'] = 'reverse'
elif query['sort_on'] == 'relevance':
del query['sort_on']
return query
def sort_options(self):
""" Sorting options for search results view. """
return (
SortOption(self.request, _(u'date (newest first'),
'EffectiveDate', reverse=True
),
SortOption(self.request, _(u'relevance'), 'relevance'),
SortOption(self.request, _(u'alphabetically'), 'sortable_title'),
)
を。あなたが最も簡単なのだろうテーマ層を使用する場合:
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="plone">
<browser:page
name="search"
layer=".interfaces.IYourCustomThemeLayer"
class=".yourmodule.MyCustomSearch"
permission="zope2.View"
for="*"
template="search.pt"
/>
<browser:page
name="updated_search"
layer=".interfaces.IYourCustomThemeLayer"
class=".yourmodule.MyCustomSearch"
permission="zope2.View"
for="Products.CMFCore.interfaces.IFolderish"
template="updated_search.pt"
/>
</configure>
あなたはplone.app.search
パッケージからsearch.pt
とupdated_search.pt
テンプレートをコピーする必要があります。
ありがとうございます!最終的な作業コードを反映するようにあなたの解決策を修正しましたが、変更内容を見ることはできません。 – hvelarde
@hvelarde:あなたの提案された編集は、査読者のために少し根本的でした。あなたのバージョンを更新しました。 –
とにかくこれらの批評家は誰ですか?人々はPloneについて何も知らず、彼らは編集をレビューできると感じていますか?ありがとう! – hvelarde