Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / Tips / Faceted Navigation

Faceted Navigation

Facet 是視覺化的查詢工具,讓使用者容易地設定查詢條件,互動而即時地呈現查詢結果。

應用情境: 課程分類搜尋 圖檔分類搜尋 collective.contact.facetednav 階層式關鍵字 (Taxonomic Checkbox) 建置管理員介面顯示項目清單 取代傳統搜尋介面

EEA FacetedNavigation 有兩個版本,https://github.com/eea/eea.facetednavigation 針對 EEA 單位自身的開發需求,https://github.com/collective/eea.facetednavigation 則是社群維護的版本。在 4.1 版本之際,支援 Faceted Settings 設定選單,會新增選項在 Action 下拉選單裡,在 5.2 版本之際,支援 plone.app.folder 和 plone.app.collection,10.0 版本後改用 z3c.form。過往程式碼的位置範例 https://svn.eionet.europa.eu/repositories/Zope/trunk/eea.faceted.inheritance/trunk,討論區在 http://groups.google.com/forum/#!forum/eea-facetednavigation

eea.facetednavigation depends on eea.jquery which provides a jquery.tree.js package. This package is in conflict with the jqtree module that mockup uses (for related items) as they both register against the global $.tree jquery plugin.

新式功能由 eea.elasticsearch 實作,成果是 PAM 資料庫

擴充模組範例: collective.contact.facetednav collective.eeafaceted.collectionwidget and collective.eeafaceted.z3ctable collective.portlet.collectionfilter

Plone5 Deprecated: Search Widget (SearchableText) Ignore Path Filter Faceted Widget in Plone5

安裝方式

Plone 4.3.7 develop.cfg 設定方式:

eggs +=
    eea.facetednavigation

為了避免 CSFS 干擾,也有人採 AngularJS 方案。在 10.0 版本之際,會同時相容 Plone4 和 Plone5,做為過渡 Plone5 的準備,Plone5 支援正式完成

下列是 Plone 4.x 環境的 develop.cfg 參考設定值:

eggs +=
    eea.facetednavigation

# Plone 4.3.4+ needs the above only, the followings seem for older Plone
zcml += eea.facetednavigation-meta eea.facetednavigation-overrides eea.facetednavigation # use eea.facetednavigation-minimal instead if don't want default ATContentTypes # from eea.fn 4.2 can dynamically register custom facted views eea.facetednavigation.views.example

eea.facetednavigation 相依於 collective.js.jqueryui 模組,依照 Plone 版本,必須選擇適用的 collective.js.jqueryui 版本:

  • Plone 5.0: collective.js.jqueryui 2.0.1 - plone.app.jquery 1.9.1.2
  • Plone 4.3: collective.js.jqueryui > 1.9.x - plone.app.jquery == 1.7.2
  • Plone 4.2: collective.js.jqueryui 1.8.x - plone.app.jquery == 1.4.4 (IDs with spaces problem)

搭配 CSRF 會造成設定介面無法生效,透過 IDisableCSRFProtection 可以先避過這問題。

不合適的版本,會遇到類似下列的 buildout 或 JavaScript 錯誤:

Got collective.js.jqueryui 1.10.3.
The constraint, 1.4.4, is not consistent with the requirement, 'plone.app.jquery>1.6'.
While:
  Installing instance.
Error: Bad constraint 1.4.4 plone.app.jquery>1.6
Uncaught TypeError: Object #<Object> has no method 'prop'

Plone 4.2.6 的 develop.cfg 範例:

eggs +=
    Products.DocFinderTab
    plone.reload
    eea.facetednavigation
    collective.js.jqueryui==1.8.16.9

zcml +=
    eea.facetednavigation-meta
    eea.facetednavigation-overrides
    eea.facetednavigation
    eea.facetednavigation.views.example

8.9 版本在 Plone 5.0.x 環境,會遇到 KeyError: 'global_defines' 錯誤,來自檔案 eea/facetednavigation/browser/template/query.pt 的 use-macro="here/global_defines/macros/defines" 段落。

新建 custom type 的場合,要在 configuration.zcml 裡加上:

<class class="my.package.content.MyType"
  zcml:condition="installed my.package.content.MyType">
  <implements interface="eea.facetednavigation.interfaces.IPossibleFacetedNavigable" />
</class>

目錄結構說明

1. edit.css / edit.js is used in edit mode: => configure-faceted.html
2. view.css / view.js is used in view mode: => facetednavigation_view
3. widget.pt / widget.py - the view and the controller of the widget.
4. tree.js / tree.py - specific files for path widget, you may not need them for your widget

只使用 Template 裡 content-core 的 METAL Slot 其他都沒用。利用 Faceted Specific Events 來觸發動態控制的功能。

eea.tool was meant to store more faceted navigation settings, but in the end it only allows you to define custom mappings between interfaces and portal_types.

辭彙表 Vocabulary 利用 Tag 欄位自動建立索引 alphabet widget issue

Hard Dependency with Archetypes

預設的排序方式在 #44 被取消,可用 TAL Expression Widget 來處理 Sort On 和 Sort Order:

# Sort On:
python:'effective' if 'c14' not in form else "FACET-EMPTY"

# Sort Order:
python:'descending' if 'c14' not in form else "FACET-EMPTY"

Dexterity Support Registry Property to Disable Diazo Rules

create new widgets in custom package

TAL Expression Facet Filter for Current Folder

python:context.absolute_url(1)
# if this doesn't work try
python:'/Plone/' + context.absolute_url(1)
python: 'published' if context.portal_membership.isAnonymousUser() else "FACET-EMPTY"

使用 Intranet Workflow 時,可改成 python: ('internal', 'external') 語法。

Path Depth Level: 0 is only the brain of the given path, 1 is it and its children

使用 select2 取代 jQuery Autocomplete 設定 Widget 的預設值 ?searchableText=fun

eea.tags 支援 Dexterity 使用 remove all 的注意事項 jQuery 1.9 不再使用 jquery.browser

Old Style Plone Portlet

Layout

eea.facetednavigation/subtypes/wrapper.py 蓋掉 atctListAlbum script

Widget

wid python:view.data.getId() 像 c1, c2 之類的屬性值,會再搭配 string:${wid}_widget 指定成 id 傳給 tal:attributes。

Checkbox:

  • widgets/checkbox/view.js
  • widgets/checkbox/edit.js
  • widgets/checkbox/widget.pt : <div class="faceted-widget faceted-checkboxes-widget faceted-count" ...>

Alphabetic widget does not work with "all, standard or tabular" views

Widget I18N

把標題的英文填到 plone.po 完成翻譯,就可以看到中英對照的標題效果。

當顯示方式的程式碼有誤時,會出現 This site encountered an error trying to fulfill your request 訊息,造成無法操作的狀況,可在網址後面加上 @@faceted_layout?layout=folder_listing 或 layout=faceted-preview-items 來調整設定值。

類似 http://localhost:8080/mysite/myfolder/@@faceted_subtyper/disable 可以停用

Sorting widget breaks on missing indices

Responsive Design Examples: www.mountaineers.org/explore/activities, www.eea.europa.eu/publications

folder_contents jquery is breaking folder_contents view on Plone 5: $.tree 名稱換掉

Programatical Configuration

export / import : test

eea.relations

PloneConf 2012 Slides

海量資料效能

Order for Criteria in Query

Infinite Loop of JavaScript Spinner

Enable PloneAdmin

Traceback (innermost last):

  • Module ZPublisher.Publish, line 196, in publish_module_standard
  • Module Products.PlacelessTranslationService.PatchStringIO, line 34, in new_publish
  • Module ZPublisher.Publish, line 146, in publish
  • Module Zope2.App.startup, line 222, in zpublisher_exception_hook
  • Module ZPublisher.Publish, line 115, in publish
  • Module ZPublisher.mapply, line 88, in mapply
  • Module ZPublisher.Publish, line 41, in call_object
  • Module Shared.DC.Scripts.Bindings, line 311, in __call__
  • Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
  • Module Products.CMFCore.FSPageTemplate, line 195, in _exec
  • Module Products.CacheSetup.patch_cmf, line 29, in FSPT_pt_render
  • Module Products.CacheSetup.patch_utils, line 9, in call_pattern
  • Module Products.CMFCore.FSPageTemplate, line 134, in pt_render
  • Module Products.CacheSetup.patch_cmf, line 77, in PT_pt_render
  • Module Products.CacheSetup.patch_utils, line 9, in call_pattern
  • Module Products.PageTemplates.PageTemplate, line 104, in pt_render
    <FSPageTemplate at /Plone/prefs_install_products_form>
  • Module TAL.TALInterpreter, line 238, in __call__
  • Module TAL.TALInterpreter, line 281, in interpret
  • Module TAL.TALInterpreter, line 749, in do_useMacro
  • Module TAL.TALInterpreter, line 281, in interpret
  • Module TAL.TALInterpreter, line 457, in do_optTag_tal
  • Module TAL.TALInterpreter, line 442, in do_optTag
  • Module TAL.TALInterpreter, line 437, in no_tag
  • Module TAL.TALInterpreter, line 281, in interpret
  • Module TAL.TALInterpreter, line 749, in do_useMacro
  • Module TAL.TALInterpreter, line 281, in interpret
  • Module TAL.TALInterpreter, line 457, in do_optTag_tal
  • Module TAL.TALInterpreter, line 442, in do_optTag
  • Module TAL.TALInterpreter, line 437, in no_tag
  • Module TAL.TALInterpreter, line 281, in interpret
  • Module TAL.TALInterpreter, line 339, in do_startTag
  • Module TAL.TALInterpreter, line 405, in attrAction_tal
  • Module Products.PageTemplates.TALES, line 227, in evaluateText
  • Module Products.PageTemplates.TALES, line 221, in evaluate
    URL: file:design/skins/eea_design/main_template.pt
    Line 58, Column 8
    Expression: <PythonExpr here.getSectionFromURL(plone_view)>
    Names:
    {'container': <PloneSite at /Plone>,
    'context': <PloneSite at /Plone>,
    'default': <Products.PageTemplates.TALES.Default instance at 0x7f22304935a8>,
    'here': <PloneSite at /Plone>,
    'loop': <Products.PageTemplates.TALES.SafeMapping object at 0x17823dd0>,
    'modules': <Products.PageTemplates.ZRPythonExpr._SecureModuleImporter instance at 0x7f22304939e0>,
    'nothing': None,
    'options': {'args': ()},
    'repeat': <Products.PageTemplates.TALES.SafeMapping object at 0x17823dd0>,
    'request': <HTTPRequest, URL=http://dev1:8080/Plone/prefs_install_products_form>,
    'root': <Application at >,
    'template': <FSPageTemplate at /Plone/prefs_install_products_form>,
    'traverse_subpath': [],
    'user': <PropertiedUser 'admin'>}
  • Module Products.PageTemplates.ZRPythonExpr, line 47, in __call__
    __traceback_info__: here.getSectionFromURL(plone_view)
  • Module Python expression "here.getSectionFromURL(plone_view)", line 1, in <expression>
  • Module Products.CMFCore.FSPythonScript, line 108, in __call__
  • Module Shared.DC.Scripts.Bindings, line 311, in __call__
  • Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
  • Module Products.CMFCore.FSPythonScript, line 164, in _exec

TypeError: <exceptions.TypeError instance at 0x176c0320> (Also, the following error occurred while attempting to render the standard error message, please see the event log for full details: getSectionFromURL() takes no arguments (1 given))

Tag Cloud Widget 如果沒有任何項目有選項被儲存,系統會記錄錯誤訊息,但不影響運作。

ERROR eea.facetednavigation.browser.error
{'__name__': 'c11',
 'catalog': u'portal_catalog',
 'cloud': u'list',
 'colormax': u'95B229',
 'colormin': u'A1BE7E',
 'count': False,
 'default': u'',
 'height': u'200',
 'hidezerocount': False,
 'index': u'origin',
 'maxchars': u'',
 'maxitems': u'50',
 'position': u'right',
 'section': u'default',
 'sizemax': u'20',
 'sizemin': u'10',
 'sortcountable': False,
 'sortreversed': False,
 'title': u'\u610f\u898b\u53cd\u6620\u4f86\u6e90',
 'vocabulary': u'origin',
 'widget': u'tagscloud'}
Traceback (most recent call last):
  File "/home/marr/shiji/buildout-cache/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 965, in do_onError_tal
    self.interpret(block)
  File "/home/marr/shiji/buildout-cache/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 343, in interpret
    handlers[opcode](self, args)
  File "/home/marr/shiji/buildout-cache/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 583, in do_setLocal_tal
    self.engine.setLocal(name, self.engine.evaluateValue(expr))
  File "/home/marr/shiji/buildout-cache/eggs/zope.tales-3.5.3-py2.7.egg/zope/tales/tales.py", line 696, in evaluate
    return expression(self)
  File "/home/marr/shiji/buildout-cache/eggs/zope.tales-3.5.3-py2.7.egg/zope/tales/pythonexpr.py", line 59, in __call__
    return eval(self._code, vars)
  File "", line 1, in 
  File "/home/marr/shiji/zinstance/src/eea.facetednavigation/eea/facetednavigation/widgets/tagscloud/counter.py", line 40, in query
    res = widget.count(brains, sequence=vocabulary.keys())
  File "/home/marr/shiji/zinstance/src/eea.facetednavigation/eea/facetednavigation/widgets/widget.py", line 351, in count
    sequence = [key for key, value in self.vocabulary()]
ValueError: too many values to unpack

eea.facetednavigation 4.0 的 minimal.zcml 包含了 collective.js.jqueryui,但 3.5 沒有 minimal.zcml 這個檔,也沒包含 collective.js.jqueryui。

faceted_counter - TypeError: expected integer key Incorrect href in pagination

Import was failing with List has not attrinute .fromUnicode UnicodeDecode Error when Catalog Names containing Unicode Characters

沒有 reindexObject() 的話,會造成 Faceted View 沒有顯示結果。

Adding New View

cp view/preview-items.pt view/wy-preview-items.pt

vi view/wy-preview-items.pt main_template -> wgye_template

vi view/configure.zcml add wy-preview-items