2

I have a very complex situation in which I need to pull out one entry from a Super Search results loop and re-inject it in a different location on the page. I'm planning on using NSM Transplant for that part and some early tests indicate it will work fine.

The tricky part is writing a conditional inside the Super Search loop that will identify the correct entry to pull out via Transplant. I want to only transplant the entry if the category or categories searched include the Primary Category of that entry - which in my case is a location.

So in plain english this is the conditional I want:

If {this_entry's_primary_category} is contained in {super_search_category} then do something with Transplant, otherwise, leave it alone

I'm using CE String so my first thought was to check if the {super_search_category} string contained the primary category URL title with strpos, something like this (this is inside exp:super_search:results):

{if "{exp:ce_str:ing strpos='{exp:primary_category entry_id='{entry_id}'}{primary_category_url_title}{/exp:primary_category}'}{super_search_category}{/exp:ce_str:ing}" != "-1"}

This always returns false - even on the entry where the primary category should be found within super search category. I think it's because {super_search_category} only works outside the exp:super_search:results tag. Is this correct?

Any suggestions for the easiest way to test to see if an entry's Primary Category is included in category or categories searched on a Super Search results page?

Edit to add some recent code examples

This is on a Super Search results page:

{exp:stash:set name="ss-cats" parse_tags="yes" parse_depth="2"}{super_search_category}{/exp:stash:set}

{exp:super_search:results 
    redirect_post="yes" 
    channel="directory"
    status="Open|Featured" 
    performance="off" 
    category_indicator="category_url_title"  
    search-words-within-words="yes"
    inclusive_categories="yes"
    orderby="vendor-group+desc+vip+desc+rating_field-rating+desc+title+asc"
    search_in="title|vendor-person|about|extended|address|awards"  
    inclusive_keywords="no"  
    where="all"  
    limit="50"  
    paginate="bottom"
}

{exp:stash:get name="ss-cats"}
<!-- lots of stuff here removed for simplicity -->

{/exp:super_search:results}

At the moment, I'm not even getting this simple stash set/get to work so I can read the value of {super_search_category} inside the results loop.

Edit for progress below:

{super_search_category} returns category URL titles if used outside results loop.

If you used INSIDE results loop it does nothing (tag is not parsed at all).

If I use Stash to save the tag output from outside the results loop it works to some extent:

{exp:stash:set name="ss-cats" parse_tags="yes" parse_depth="1"}{super_search_category}{/exp:stash:set}
Stash get SS cats outside results: {exp:stash:get name="ss-cats"}

{exp:super_search:results
    redirect_post="yes"
    channel="directory"
    status="Open|Featured"
    performance="off"
    category_indicator="category_url_title" 
    search-words-within-words="yes"
    inclusive_categories="yes"
    orderby="vendor-group+desc+vip+desc+rating_field-rating+desc+title+asc"
    search_in="title|vendor-person|about|extended|address|awards" 
    inclusive_keywords="no" 
    where="all" 
    limit="50" 
    paginate="bottom"
}

Stash get SS cats inside results: {exp:stash:get name="ss-cats"}

{/exp:super_search:results}

In this case the stash:get outside results works fine, but the stash:get inside results returns something different (a completely different category name - which isn't even the Super Search category!).

So I fail to see how I can read {super_search_category} from within the results in order to use it in a conditional.

  • Another idea I tried is using Super Search category conditionals like this {if super_search_category_{exp:primary_category entry_id='{entry_id}'}{primary_category_url_title}{/exp:primary_category}} or even hard-coding a test category like this {if super_search_category_akl} but neither work. Again, I think it's because all of the Super Search options for outputing or evaluating searched categories are only available OUTSIDE the search results loop. I can't find anything that's available INSIDE! @solspace, are there any tags that work inside the results loop? – Benek Lisefski Apr 27 '14 at 22:08
1

Consider checking out Stash instead of Transplant using it's set_list & get_list's -> match / against params. (I probably need more info to help with the regex if any)

See this wiki article for Filtering Lists with match against. Note: in that example Mark is manually creating the list but, you'd do it with Super Search (or channel entries tags etc.) and use the Primary Category to filter against (if and when it exists.)

Also, this EESE answer appears to have accomplished something similar (possibly the opposite?) to what you want using Stash and Active Record; an add-on which is often recommend over using the Query Module.

| improve this answer | |
  • Those look like good solutions, but unfortunately none of them touch on the part I'm struggling with most. I haven't found a way to successfully test if the Primary Category is included in the Super Search searched categories. I'm not testing against a predetermined category where I can simply input the cat ID. I need to see if the dynamic list of categories searched includes the Primary category for each entry, and then in that case do something special with that entry. Whether it's Stash or Transplant used for moving it doesn't particular matter. – Benek Lisefski Apr 26 '14 at 7:41
0

Have you tried Plv Check If plugin?

| improve this answer | |
  • Thanks for the suggestion but it doesn't solve my problem. The biggest challenge seems to be getting a list of searched categories to output inside the search results loop. All of the Super Search tags for this task seem to be only available outside the search results. – Benek Lisefski Apr 27 '14 at 22:10
0

Does {super_search_keywords} contain the category name when the search is on a category? Unlike {super_search_category} which works only outside of the results loop, {super_search_keywords} can be used within it.

If that doesn't work, the one thing to say about Stash that maybe isn't clear from @Natetronn's answer, is that you could use Stash to capture the value of {super_search_category} outside of the results loop, and then use that value inside the results loop.

Using Stash to solve your issue would be slightly complicated, so best to see if {super_search_keywords} solves your issue first. And, maybe NSM Transplant could work similarly to Stash in this regard. But Stash is particularly good at letting you move values in and out of contexts and perform conditionals on those values. (The hard part, of course, is figuring out which freakin' context each part of your code is in, in relation to EE's outside-to-inside parse order…)

| improve this answer | |
  • The keyword does not contain category so I can't rely on that. Your suggestion to use Stash to capture the {super_search_category} outside the loop and then use it inside is exactly what I tried in my most recent attempt however I couldn't get it to work. For some reason I'm having a difficult time getting {super_search_category} to work reliably, even outside the results loop, and can't successfully use it as a conditional even if captured first by stash outside results. So I'm stuck where I originally was, trying to find away to test the SS category against each entry's primary category. – Benek Lisefski Apr 30 '14 at 21:00
  • I just edited question to add some template code examples – Benek Lisefski Apr 30 '14 at 21:06
0

I want to share my final solution in case anyone else runs across a similar situation.

My goal was in two parts:

  1. Identify which entries had their Primary Category equal to one of the Super Search categories from {super_search_category} string.

  2. Move that entry to the top of the search results to bypass the normal sort order.

I accomplished it like this (lots of code removed to show just the relevant parts):

<?php $cats = explode(" ", '{super_search_category}'); ?>

<ul class="directory">  

{exp:super_search:results 
    redirect_post="yes" 
    channel="directory"
    status="Open|Featured" 
    performance="off" 
    category_indicator="category_url_title"  
    search-words-within-words="yes"
    inclusive_categories="yes"
    orderby="vendor-group+desc+vip+desc+rating_field-rating+desc+title+asc"
    search_in="title|vendor-person|about|extended|address|awards"  
    inclusive_keywords="no"  
    where="all"  
    limit="50"  
    paginate="bottom"
}

    <?php $group = "{vendor-group}"; ?>
    <?php $primeCat = "{exp:primary_category entry_id='{entry_id}'}{primary_category_url_title}{/exp:primary_category}"; ?>

    <li
        <?php if ($group == "10 - Platinum" && in_array($primeCat, $cats) !== false) { ?>
            data-platinum="primary-platinum"
        <?php } ?>
    >   
    </li>
{/exp:super_search:results}

</ul>

<script>
    $(function () {
        $(".directory li[data-platinum='primary-platinum']").prependTo($("ul.directory"));
    });
</script>

Comparing the search category string to the primary category had to be done with PHP since that tag only works outside the results loop. Even with Stash I couldn't get it to work because of parse order issues.

After banging my head over multiple ways to try to transplant the entry to the top of the list using NSM Transplant, Stash, Embeds, or extra search results tags, I decided it was far easier to do it on the front-end with javascript!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.