Answers.Body: <p>The reason you're getting an error when trying to merge the two search results is that they are not technically arrays, but elementCriteriaModels. To convert them to actual arrays you would need to use the <code>find()</code> method.</p>
  
  <pre><code>{% set entries = craft.entries.search(query).order('score').find() %}
  {% set categories = craft.categories.search(query).order('score').find() %}
  {% set results = categories|merge(entries) %}
  </code></pre>
  
  <p>The problem with this is that the sort order will be wrong (showing all categories and then all entries). Although you could potentially sort the results array using something like the <a href="http://michaelrog.com/craft/lagniappe/supersort">supersort plugin</a>.</p>
  
  <p>The other option to consider is redesigning the database so that there is nothing in categories that needed to be searched for, which might simplify things in the end.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-05T19:55:46.340Z
Answers.Text: I don't think you have access to score from the template, so sorting the merged array is not possible.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-06T23:06:58.350Z
Answers.Text: Thanks. So in the end I added the content I wanted searched into a Structure that matches the Category set up, and matched them accordingly both for display on a page, and a redirect from the search result.
Answers.UserDisplayName: Jack McKenzie
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-14T12:10:00.430Z
Answers.Text: @Douglas there's a FR to [expose the score to the templates](http://feedback.buildwithcraft.com/forums/285221-feature-requests/suggestions/7179014-expose-the-search-score-for-entries-in-search-resu).
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-05T13:20:56.247Z
Answers.LastActivityDate: 2015-04-05T13:20:56.247Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>I have a search page. I can search either categories or entries using</p>
  
  <pre><code>{% set entries = craft.entries.search(query).order('score') %}
  {% set categories = craft.categories.search(query).order('score') %}
  </code></pre>
  
  <p>I have added quite a bit of content in each category i.e. what it's all about etc. and I would like this content returned like a standard search result going to the category URL (it works when I search categories only)</p>
  
  <p>I've tried to merge the above two arrays </p>
  
  <pre><code>{% set results = categories | merge (entries) %}
  </code></pre>
  
  <p>But that's obviously not how you do it because it throws a craft error.</p>
  
  <p>Now, I guess I could return the results of one, and then the other, but I was hoping to have the score create a more sensible order of relevant results. </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-04T06:36:16.417Z
Comments.Text: My workaround (so not an answer), it put all the content for each category into a matching structure section, which in turn has the category as a field. So when this structure entry is found in the search, it in turn redirects the category field URL, in effect getting around the problem. It just means that when I add a category I have to go and add a matching entry.
Comments.UserDisplayName: Jack McKenzie
Tags: <templating><categories><search>
Title: How do I combine search for categories and entries into one set of search results?
ThreadText: # How do I combine search for categories and entries into one set of search results?
  
  (Asked by: username_0 on 2015-04-04)
  
  I have a search page. I can search either categories or entries using
  
  ```
  {% set entries = craft.entries.search(query).order('score') %}
  {% set categories = craft.categories.search(query).order('score') %}
  
  ```
  
  I have added quite a bit of content in each category i.e. what it's all about etc. and I would like this content returned like a standard search result going to the category URL (it works when I search categories only)
  
  I've tried to merge the above two arrays
  
  ```
  {% set results = categories | merge (entries) %}
  
  ```
  
  But that's obviously not how you do it because it throws a craft error.
  
  Now, I guess I could return the results of one, and then the other, but I was hoping to have the score create a more sensible order of relevant results.
  
  **Tags:** templating, categories, search
  
  > **Comments:**
  > **username_0**: My workaround (so not an answer), it put all the content for each category into a matching structure section, which in turn has the category as a field. So when this structure entry is found in the search, it in turn redirects the category field URL, in effect getting around the problem. It just means that when I add a category I have to go and add a matching entry.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-04-05. Score: 5 | Accepted answer
  
  The reason you're getting an error when trying to merge the two search results is that they are not technically arrays, but elementCriteriaModels. To convert them to actual arrays you would need to use the `find()` method.
  
  ```
  {% set entries = craft.entries.search(query).order('score').find() %}
  {% set categories = craft.categories.search(query).order('score').find() %}
  {% set results = categories|merge(entries) %}
  
  ```
  
  The problem with this is that the sort order will be wrong (showing all categories and then all entries). Although you could potentially sort the results array using something like the [supersort plugin](http://michaelrog.com/craft/lagniappe/supersort).
  
  The other option to consider is redesigning the database so that there is nothing in categories that needed to be searched for, which might simplify things in the end.
  
  > **Comments:**
  > **username_2**: I don't think you have access to score from the template, so sorting the merged array is not possible.  
  > **username_0**: Thanks. So in the end I added the content I wanted searched into a Structure that matches the Category set up, and matched them accordingly both for display on a page, and a redirect from the search result.  
  > **username_2**: @username_1 there's a FR to [expose the score to the templates](http://feedback.buildwithcraft.com/forums/285221-feature-requests/suggestions/7179014-expose-the-search-score-for-entries-in-search-resu).  
  
  ---
  
  