查询中的投影

时间:2015-03-27 09:49:10

标签: solr lucene liferay liferay-6

在solr中,有参数“fl”,它在查询中提供投影。如何在liferay中实现相同的功能?

提前感谢您的帮助和建议。

1 个答案:

答案 0 :(得分:0)

fl 不是SOLR查询中的投影,它只是选择结果字段。

首先:Liferay使用Lucene作为搜索引擎 - 而不是SOLR。

如果“ in liferay ”表示“在UI中”:您无法在UI中选择结果字段。结果是由Lucene过滤的数据库中的对象(对于某些搜索表单和一些配置,即使没有Lucene使用SQL直接从数据库中检索结果)。

如果“ in liferay ”表示“ in API ”:如果以低级别访问Lucene索引器,则可以选择结果字段({{1 }}方法无济于事)并使用...ServiceUtil.search

FieldSelector

您也可以使用任何其他查询方法。 请查看IndexSearcher indexSearcher = LuceneHelperUtil.getIndexSearcher(companyId); IndexReader indexReader = indexSearcher.getIndexReader(); FieldSelector fieldSelector = new FieldSelector() { public FieldSelectorResult accept(String fieldName) { // Only return "my-field" if ("my-field".equals(fieldName)) { return FieldSelectorResult.LOAD_AND_BREAK; } return FieldSelectorResult.NO_LOAD; } }; TopDocs topDocs = indexSearcher.query(luceneQuery, maxDocuments); // Retrieve only the selected fields for the hits List<Document> results = new ArrayList<Document>(); for (int i = 0; i < topDocs.scoreDocs.length; i++) { results.add(indexReader.document(topDocs.scoreDocs[i].doc, fieldSelector)); } ,了解如何正确构建查询。

相关问题