(你) 6 年之前 [...] (Previous parts of this series can be found here (part 1), here (part 2) and here (part 3) [...] Read More 请登录以投票。 以……回复 取消
(你) 6 年之前 [...] Previous parts of this series can be found here (part 1), here (part 2), here (part 3) and here (part 4). In the final part of this blog series few more interesting features are added to the... [...] Read More 请登录以投票。 以……回复 取消
Aastha Saxena 5 年之前 Hi I tried to implement autocomplete-suggestions using elastic search engine following this post. Step 1: Indexed my keyword "news" with below code when number of results of the Hits more than my threshold: _indexWriterHelper.indexKeyword(companyId,"news",0,SuggestionConstants.TYPE_QUERY_SUGGESTION, locale); Step 2: on checking Elastic engine server I found my keyword is indexed as below: url:http://localhost:9200/liferay-20115/_search?pretty&q=news "hits" : [ { "_index" : "liferay-20115", "_type" : "querySuggestion", "_id" : "20115_spellCheckWord_6RitQgdCR1qG3k8CzKTjdw==", "_score" : 1.9425526, "_source" : { "uid" : "20115_spellCheckWord_6RitQgdCR1qG3k8CzKTjdw==", "companyId" : "20115", "groupId" : "0", "keywordSearch_en_US" : "news", "priority" : "0.0", "spellCheckWord" : "true" } Step 3: Then tried to find the indexed keyword with below code: field = "keywordSearch_en_US"; keyword = "news"; TermSuggester termSuggester = new TermSuggester("termSuggester", field, keyword); /** Method 1 using QuerySuggester of com.liferay.portal.kernel.search.suggest.QuerySuggester */ SuggesterResults suggesters1 = _querySuggester.suggest(searchContext, termSuggester); Collection<SuggesterResult> suggesterResults = suggesters1.getSuggesterResults(); if (suggesterResults != null) { for (SuggesterResult suggesterResult : suggesterResults) { for (Entry entry : suggesterResult.getEntries()) { for (Option option : entry.getOptions()) { if (!suggestions.contains(option.getText())) { suggestions.add(option.getText()); } } } } } /** Method 2 using indexSearcher directly of com.liferay.portal.kernel.search.IndexSearcher*/ SearchEngine searchEngine = SearchEngineHelperUtil.getSearchEngine(searchContext.getSearchEngineId()); IndexSearcher indexSearcher = searchEngine.getIndexSearcher(); SuggesterResults suggesters2 = indexSearcher.suggest(searchContext, termSuggester); suggesterResults = suggesters2.getSuggesterResults(); if (suggesterResults != null) { for (SuggesterResult suggesterResult : suggesterResults) { for (Entry entry : suggesterResult.getEntries()) { for (Option option : entry.getOptions()) { if (!suggestions.contains(option.getText())) { suggestions.add(option.getText()); } } } } } But in both the methods(method1 and Method2) entry.getOptions() is coming empty list. I am not sure what should be the value of field while initializing termSuggester. for the response in advance. 请登录以投票。 以……回复 取消 Petteri Karttunen Aastha Saxena 5 年之前 - 编辑过的 Hi Aastha and sorry for the delay! The field you should be querying is keywordSearch_{LANGUAGE_ID} if you are using the standard mapping but as this is an "old" post, I'd like to ask: - Which portal and ES versions are you using (seems to be 6.1)? Embedded or standalone? - If you are using GSearch, which version of the Core? - Are you using the standard Liferay ES adapter or the custom one? There can be a couple other reasons than the field name for empty results so I can only try to give some hints (before knowing you app versions): - If you are using standalone ES, have you checked the log? If you were querying an unmapped field or there was a syntactical error etc. you should get an error. - If you are using LR 7.1, there was a problem in the standard adapter. See workaround here: https://github.com/peerkar/liferay-portal/blob/fbdbd757a017a7f8ea8ae3e4f23a43ff6fe924fe/modules/apps/portal-search-elasticsearch6/portal-search-elasticsearch6-impl/src/main/java/com/liferay/portal/search/elasticsearch6/internal/suggest/AggregateSuggesterTranslatorImpl.java#L61 I've only Phrase and Completion suggesters implement there but if you haven't done it already, please take a look at the current implementation in GSearch: https://github.com/peerkar/liferay-gsearch/blob/master/gsearch-core-impl/src/main/java/fi/soveltia/liferay/gsearch/core/impl/suggest/GSearchKeywordSuggesterImpl.java and the corresponding default configuration: https://github.com/peerkar/liferay-gsearch/blob/master/gsearch-core-impl/src/main/resources/configs/fi.soveltia.liferay.gsearch.core.impl.configuration.KeywordSuggesterConfiguration.config I hope this helps, Petteri 请登录以投票。 以……回复 取消
Petteri Karttunen Aastha Saxena 5 年之前 - 编辑过的 Hi Aastha and sorry for the delay! The field you should be querying is keywordSearch_{LANGUAGE_ID} if you are using the standard mapping but as this is an "old" post, I'd like to ask: - Which portal and ES versions are you using (seems to be 6.1)? Embedded or standalone? - If you are using GSearch, which version of the Core? - Are you using the standard Liferay ES adapter or the custom one? There can be a couple other reasons than the field name for empty results so I can only try to give some hints (before knowing you app versions): - If you are using standalone ES, have you checked the log? If you were querying an unmapped field or there was a syntactical error etc. you should get an error. - If you are using LR 7.1, there was a problem in the standard adapter. See workaround here: https://github.com/peerkar/liferay-portal/blob/fbdbd757a017a7f8ea8ae3e4f23a43ff6fe924fe/modules/apps/portal-search-elasticsearch6/portal-search-elasticsearch6-impl/src/main/java/com/liferay/portal/search/elasticsearch6/internal/suggest/AggregateSuggesterTranslatorImpl.java#L61 I've only Phrase and Completion suggesters implement there but if you haven't done it already, please take a look at the current implementation in GSearch: https://github.com/peerkar/liferay-gsearch/blob/master/gsearch-core-impl/src/main/java/fi/soveltia/liferay/gsearch/core/impl/suggest/GSearchKeywordSuggesterImpl.java and the corresponding default configuration: https://github.com/peerkar/liferay-gsearch/blob/master/gsearch-core-impl/src/main/resources/configs/fi.soveltia.liferay.gsearch.core.impl.configuration.KeywordSuggesterConfiguration.config I hope this helps, Petteri 请登录以投票。 以……回复 取消