'author' 字段的 CKAN 方面给出标记化值
CKAN facets for 'author' field gives tokenized values
我已通过实施 dataset_facets()
在我的数据集搜索中添加了一个方面,遵循此文档:
http://docs.ckan.org/en/ckan-2.7.3/extensions/plugin-interfaces.html#ckan.plugins.interfaces.IFacets
更具体地说,我使用以下代码为 author
字段添加了一个方面:
def dataset_facets(self, facets_dict, package_type):
if package_type == 'dataset':
facets_dict['author'] = toolkit._(u'Author')
return facets_dict
出乎意料的是,方面列表中显示的方面值是标记化的小写作者姓名,而不是全名。即,如果我有这些作者姓名:
[ 'Amt für Statistik', 'Senatsverwaltung für Kultur', 'VBB' ]
然后我得到以下构面值:
[ 'amt', 'fur', 'kultur', 'statistik', 'senatsverwaltung', 'vbb' ]
这似乎是 author
字段的 Solr 架构条目的原因,它表示 type="textgen"
。不太了解 Solr,我对此进行了试验并将其更改为 type="string"
,现在它可以工作了,即,我将完整的作者姓名作为方面值。
我的问题:
- 为什么
textgen
被选为 author
字段?
- 选择
string
是否可能会破坏 CKAN 中的其他内容?到目前为止,我没有发现任何问题。
- 有没有更好的方法来让分面基于
textgen
类型的字段(例如,将字段复制到类型为 string
的新字段)?
不同之处在于,将其更改为字符串字段后,针对同一字段进行搜索将需要精确匹配。由于没有进行任何处理,字符串不会被分成单独的部分或小写等,因此要获得与字段的匹配,必须使用完整的搜索字符串,Amt für Statistik
。只是 statistik
将不再命中。
我对 CKAN 不熟悉,所以除非它使用字段进行搜索,否则它应该可以正常工作。但是,如果它也被用于搜索,您的下一个建议将是解决它的首选方法。
将字段复制到一个单独的string
字段中用于分面是解决此类问题的首选方法 - 一个字段用于搜索,一个字段用于分面。使用不同的定义来获得不同的行为并选择最适合您正在做的事情的字段。
为了完整起见,这是我根据 :
所做的
在 schema.xml
中定义一个额外的作者字段:
<!-- Copy the author field into authorString, and treat as a string
(rather than textgen). This allows to use author as a facet for search. -->
<field name="author_string" type="string" indexed="true" stored="false" />
将author
字段复制到author_string
:
<copyField source="author" dest="author_string"/>
使用新字段在 CKAN 中生成分面:
def dataset_facets(self, facets_dict, package_type):
if package_type == 'dataset':
facets_dict['author_string'] = toolkit._(u'Author')
return facets_dict
现在我可以拥有一个包含完整字符串的分面,但仍然搜索部分字符串。
我已通过实施 dataset_facets()
在我的数据集搜索中添加了一个方面,遵循此文档:
http://docs.ckan.org/en/ckan-2.7.3/extensions/plugin-interfaces.html#ckan.plugins.interfaces.IFacets
更具体地说,我使用以下代码为 author
字段添加了一个方面:
def dataset_facets(self, facets_dict, package_type):
if package_type == 'dataset':
facets_dict['author'] = toolkit._(u'Author')
return facets_dict
出乎意料的是,方面列表中显示的方面值是标记化的小写作者姓名,而不是全名。即,如果我有这些作者姓名:
[ 'Amt für Statistik', 'Senatsverwaltung für Kultur', 'VBB' ]
然后我得到以下构面值:
[ 'amt', 'fur', 'kultur', 'statistik', 'senatsverwaltung', 'vbb' ]
这似乎是 author
字段的 Solr 架构条目的原因,它表示 type="textgen"
。不太了解 Solr,我对此进行了试验并将其更改为 type="string"
,现在它可以工作了,即,我将完整的作者姓名作为方面值。
我的问题:
- 为什么
textgen
被选为author
字段? - 选择
string
是否可能会破坏 CKAN 中的其他内容?到目前为止,我没有发现任何问题。 - 有没有更好的方法来让分面基于
textgen
类型的字段(例如,将字段复制到类型为string
的新字段)?
不同之处在于,将其更改为字符串字段后,针对同一字段进行搜索将需要精确匹配。由于没有进行任何处理,字符串不会被分成单独的部分或小写等,因此要获得与字段的匹配,必须使用完整的搜索字符串,Amt für Statistik
。只是 statistik
将不再命中。
我对 CKAN 不熟悉,所以除非它使用字段进行搜索,否则它应该可以正常工作。但是,如果它也被用于搜索,您的下一个建议将是解决它的首选方法。
将字段复制到一个单独的string
字段中用于分面是解决此类问题的首选方法 - 一个字段用于搜索,一个字段用于分面。使用不同的定义来获得不同的行为并选择最适合您正在做的事情的字段。
为了完整起见,这是我根据
在 schema.xml
中定义一个额外的作者字段:
<!-- Copy the author field into authorString, and treat as a string
(rather than textgen). This allows to use author as a facet for search. -->
<field name="author_string" type="string" indexed="true" stored="false" />
将author
字段复制到author_string
:
<copyField source="author" dest="author_string"/>
使用新字段在 CKAN 中生成分面:
def dataset_facets(self, facets_dict, package_type):
if package_type == 'dataset':
facets_dict['author_string'] = toolkit._(u'Author')
return facets_dict
现在我可以拥有一个包含完整字符串的分面,但仍然搜索部分字符串。