Answers.Body: <p>You can use the Twig <a href="https://craftcms.com/docs/templating/filters#group" rel="noreferrer">group filter</a>.</p>
  
  <pre><code>{% set entries = allowedSearchableEntries.search(query).order('score').limit(100) %}
  
  {% set entriesBySection = entries|group('section') %}
  
  {% for section, entriesInSection in entriesBySection %}
      &lt;h2&gt;{{ section }}&lt;/h2&gt;
  
      &lt;ul&gt;
          {% for entry in entriesInSection %}
              &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
          {% endfor %}
      &lt;/ul&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-20T17:45:26.047Z
Answers.Text: Brilliant! Do you know also how I could change the order of sections before doing the group filter? Currently it pulls from the section order in the CP.
Answers.UserDisplayName: 4midori
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-18T21:43:44.950Z
Answers.LastActivityDate: 2017-02-18T21:43:44.950Z
Answers.UserDisplayName: Aaron Berkowitz
Body: <p>How do I group entries by section? I have search results:</p>
  
  <pre><code>{% set entries = allowedSearchableEntries.search(query).order('score').limit(100) %}
  </code></pre>
  
  <p>But I want to have</p>
  
  <p><strong>SECTION NAME</strong>
  entry 1
  entry 4
  entry 6</p>
  
  <p><strong>SECTION NAME</strong>
  entry 3
  entry 12</p>
  
  <p>etc.</p>
  
Tags: <entries><group>
Title: Group entries by section
ThreadText: # Group entries by section
  
  (Asked by: username_0 on 2017-02-17)
  
  How do I group entries by section? I have search results:
  
  ```
  {% set entries = allowedSearchableEntries.search(query).order('score').limit(100) %}
  
  ```
  
  But I want to have
  
  **SECTION NAME**
  entry 1
  entry 4
  entry 6
  
  **SECTION NAME**
  entry 3
  entry 12
  
  etc.
  
  **Tags:** entries, group
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-02-18. Score: 6 | Accepted answer
  
  You can use the Twig [group filter](https://craftcms.com/docs/templating/filters#group).
  
  ```
  {% set entries = allowedSearchableEntries.search(query).order('score').limit(100) %}
  
  {% set entriesBySection = entries|group('section') %}
  
  {% for section, entriesInSection in entriesBySection %}
      <h2>{{ section }}</h2>
  
      <ul>
          {% for entry in entriesInSection %}
              <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
          {% endfor %}
      </ul>
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: Brilliant! Do you know also how I could change the order of sections before doing the group filter? Currently it pulls from the section order in the CP.  
  
  ---
  
  