<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>CompletionSuggester to find search suggestions</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121260009" />
  <subtitle>CompletionSuggester to find search suggestions</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121260009</id>
  <updated>2026-04-07T02:00:19Z</updated>
  <dc:date>2026-04-07T02:00:19Z</dc:date>
  <entry>
    <title>CompletionSuggester to find search suggestions</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121260008" />
    <author>
      <name>Beatriz Valdés Suárez</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121260008</id>
    <updated>2021-11-24T15:28:34Z</updated>
    <published>2021-11-24T15:27:58Z</published>
    <summary type="html">&lt;p&gt;(Liferay 7.2) I have a development in which autocomplete is required
  in the search input of the SearchBar. To do this, we are implementing
  a resource that is responsible for obtaining the suggestions as the
  user writes. Both the spell checker and the PhraseSuggester give me
  results but not all the expected ones. Also, I don't see how to use a CompletionSuggester.&lt;/p&gt;
&lt;p&gt;If I do an index search:  &lt;a
    href="http://localhost:9200/_search?pretty=true&amp;amp;q=crisis AND type:querySuggestion "
    target="_blank"&gt;http://localhost:9200/_search?pretty=true&amp;amp;q=crisis AND
    type:querySuggestion &lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I get this hits:&lt;/p&gt;
&lt;p&gt;
  &lt;code&gt;&amp;quot;hits&amp;quot;: {&lt;br /&gt; &amp;quot;total&amp;quot;: 2,&lt;br /&gt;
    &amp;quot;max_score&amp;quot;: 11.147705,&lt;br /&gt; &amp;quot;hits&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt; &amp;quot;_index&amp;quot;: &amp;quot;liferay-20101&amp;quot;,&lt;br /&gt;
    &amp;quot;_type&amp;quot;: &amp;quot;LiferayDocumentType&amp;quot;,&lt;br /&gt;
    &amp;quot;_id&amp;quot;:
    &amp;quot;20101_keywordSearch_De/BW/dejFNL0siq+HU2Ew==&amp;quot;,&lt;br /&gt;
    &amp;quot;_score&amp;quot;: 11.147705,&lt;br /&gt; &amp;quot;_source&amp;quot;: {&lt;br /&gt;
    &lt;strong&gt;&amp;quot;keywordSearch_es_ES&amp;quot;: &amp;quot;crisis&amp;quot;,&lt;/strong&gt;
    &lt;br /&gt; &amp;quot;uid&amp;quot;:
    &amp;quot;20101_keywordSearch_De/BW/dejFNL0siq+HU2Ew==&amp;quot;,&lt;br /&gt;
    &amp;quot;companyId&amp;quot;: &amp;quot;20101&amp;quot;,&lt;br /&gt; &amp;quot;groupId&amp;quot;:
    &amp;quot;0&amp;quot;,&lt;br /&gt; &amp;quot;languageId&amp;quot;:
    &amp;quot;es_ES&amp;quot;,&lt;br /&gt; &amp;quot;priority&amp;quot;:
    &amp;quot;0.0&amp;quot;,&lt;br /&gt; &amp;quot;type&amp;quot;:
    &amp;quot;querySuggestion&amp;quot;&lt;br /&gt; }&lt;br /&gt; },&lt;br /&gt; {&lt;br /&gt;
    &amp;quot;_index&amp;quot;: &amp;quot;liferay-20101&amp;quot;,&lt;br /&gt;
    &amp;quot;_type&amp;quot;: &amp;quot;LiferayDocumentType&amp;quot;,&lt;br /&gt;
    &amp;quot;_id&amp;quot;:
    &amp;quot;20101_keywordSearch_PyewLylt4i0IheiXHaUzgg==&amp;quot;,&lt;br /&gt;
    &amp;quot;_score&amp;quot;: 10.469259,&lt;br /&gt; &amp;quot;_source&amp;quot;: {&lt;br /&gt;
    &lt;strong&gt;&amp;quot;keywordSearch_es_ES&amp;quot;: &amp;quot;La crisis macabea&amp;quot;,&lt;/strong&gt;
    &lt;br /&gt; &amp;quot;uid&amp;quot;:
    &amp;quot;20101_keywordSearch_PyewLylt4i0IheiXHaUzgg==&amp;quot;,&lt;br /&gt;
    &amp;quot;companyId&amp;quot;: &amp;quot;20101&amp;quot;,&lt;br /&gt; &amp;quot;groupId&amp;quot;:
    &amp;quot;0&amp;quot;,&lt;br /&gt; &amp;quot;languageId&amp;quot;:
    &amp;quot;es_ES&amp;quot;,&lt;br /&gt; &amp;quot;priority&amp;quot;:
    &amp;quot;0.0&amp;quot;,&lt;br /&gt; &amp;quot;type&amp;quot;:
    &amp;quot;querySuggestion&amp;quot;&lt;br /&gt; }&lt;br /&gt; }&lt;br /&gt; ]&lt;br /&gt; } &lt;/code&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;If I check with the PhraseSuggester:&lt;/p&gt;
&lt;p style="margin-left: 40.0px;"&gt;
  &lt;br /&gt; PhraseSuggester suggester = new PhraseSuggester
  (&amp;quot;phraseSuggester&amp;quot;, field, keyword);&lt;br /&gt; suggester.setSize
  (5);&lt;br /&gt; [...] = indexSearcher.suggest (searchContext, suggester);&lt;/p&gt;
&lt;p&gt;
  &lt;br /&gt; where field = keywordSearch_es_ES and keyword = crisis&lt;br /&gt;
  The PhraseSuggester only returns the first result, that of a word, but
  not the second, which is a phrase.&lt;/p&gt;
&lt;p&gt;Without using the Phrase Suggester:&lt;/p&gt;
&lt;p style="margin-left: 40.0px;"&gt;
  &lt;br /&gt; IndexSearcherHelperUtil.suggestKeywordQueries (searchContext, 10);&lt;/p&gt;
&lt;p&gt;
  &lt;br /&gt; where in the searchContext.setKeyword (&amp;quot;crisis&amp;quot;), no
  results are returned&lt;br /&gt; (If I search for &amp;quot;cirsis&amp;quot;, it
  does return the result &amp;quot;crisis&amp;quot;, so the search by word does it)&lt;/p&gt;
&lt;p&gt;In the mapping that Liferay generates, I see that the field where the
  searches are stored, is of type text, not &amp;quot;completion&amp;quot;:&lt;/p&gt;
&lt;p style="margin-left: 40.0px;"&gt;
  &lt;br /&gt; &amp;quot;keywordSearch_es_ES&amp;quot;: {&lt;br /&gt; &amp;quot;type&amp;quot;:
  &amp;quot;text&amp;quot;,&lt;br /&gt; &amp;quot;store&amp;quot;: true,&lt;br /&gt;
  &amp;quot;term_vector&amp;quot;: &amp;quot;with_positions_offsets&amp;quot;,&lt;br /&gt;
  &amp;quot;analyzer&amp;quot;: &amp;quot;spanish&amp;quot;,&lt;br /&gt;
  &amp;quot;search_analyzer&amp;quot;: &amp;quot;liferay_analyzer_es&amp;quot;&lt;br /&gt; },&lt;/p&gt;
&lt;p&gt;
  &lt;br /&gt; Using the CompletionSuggester on the
  &amp;quot;keywordSearch_es_ES&amp;quot;, Liferay does not allow me either. And
  I don't see another field in the mapping that is of type &amp;quot;completion&amp;quot;&lt;/p&gt;
&lt;p&gt;Isn't there a way that, given a word, get all the suggestions,
  including sentences, where that word has been used? In the example
  above, let the value &amp;quot;crisis&amp;quot; get the phrase hit:
    &amp;quot;&lt;code&gt;La crisis macabea&lt;/code&gt;&amp;quot;&lt;/p&gt;</summary>
    <dc:creator>Beatriz Valdés Suárez</dc:creator>
    <dc:date>2021-11-24T15:27:58Z</dc:date>
  </entry>
</feed>
