【发布时间】:2014-07-02 05:45:31
【问题描述】:
我想实现自定义搜索portlet,以便可以搜索属于自定义结构的属性。 假设我创建了一个名为“文学”的结构,其中包含作者、内容、标题、注释、章节等属性。 我想创建“高级”搜索,我可以在哪里选择特定的结构类型(文学、裁决或立法),用这些结构类型的另一个属性表示的特定部分(例如,仅选择带有 PPV 部分的文献或带有 APS 部分的文献)等等
我尝试使用分面搜索,但不知道如何将这些结构的属性包含到查询中: 这是我的“搜索”代码:
SearchContext searchContext = SearchContextFactory.getInstance(httpServletRequest);
Map<String, Serializable> attributes = new HashMap<String, Serializable>();
attributes.put(Field.TITLE, "some word");
attributes.put("paginationType", "regular");
searchContext.setAttributes(attributes);
Facet assetEntriesFacet = new AssetEntriesFacet(searchContext);
assetEntriesFacet.setStatic(true);
searchContext.addFacet(assetEntriesFacet);
Facet scopeFacet = new ScopeFacet(searchContext);
scopeFacet.setStatic(true);
searchContext.addFacet(scopeFacet);
String[] entryClassNames = { JournalArticle.class.getName() };
searchContext.setEntryClassNames(entryClassNames);
hits = FacetedSearcher.getInstance().search(searchContext);
List<Document> docs = hits.toList();
那么如何在构面搜索中包含我的结构特定属性,例如“部分”等...
我的另一个问题是标点符号有问题。假设标题包含单词“Právo”。当我使用单词“pravo”运行搜索时,它会带来 0 个结果,但是当我使用“právo”运行搜索时,它会找到我的结果。有没有标点符号搜索的解决方法?
谢谢, 帕特里克
【问题讨论】:
-
对您的问题的部分回答:如果您将结构字段保持为可索引,那么 Lucene/solr 将以“web_content/”为前缀的名称存储它。您可以使用 web_content/fieldname 在查询中添加结构字段
-
嗨,你能写更多细节吗?我试图像这样添加结构字段来查询:attributes.put("web_content/section", "some section");但它返回所有期刊文章,不仅是具有指定结构字段和值的期刊文章。