SimpleSearch Parameters

In addition to searching the entire site the user can choose a specific folder (container) to search. For example:

All Categories
Category 1
Category 2
Category 3

It was working fine but now only the (default) sitewide option returns a result, the custom options (categories) return nothing. Originally I set this up with getResources but have since moved to pdoResources if that matters.

Search form:

<form class="simplesearchForm" action="[[~[[+landing:default=`[[*id]]`]]]]" method="[[+method:default=`get`]]">
	<fieldset>
		<select data-placeholder="Select a category..." class="simpleSearch" name="parent" id="parent">
			<option value=""></option>
			<option value="0">All Categories</option>
[[!pdoResources?
	&parents=0
	&tpl=Search Option
	&where={"isfolder:=":"1"}
	&sortby=alias
	&sortdir=ASC
	&depth=0
	&includeContent=1
	&resources=2,3,4
]]
		</select>
		<input type="text" name="[[+searchIndex]]" id="[[+searchIndex]]" value="[[+searchValue]]" placeholder="">
		<input type="hidden" name="id" value="[[+landing:default=[[*id]]]]">
		<input type="submit" class="button" value="[[%simplesearch.search? &namespace=simplesearch &topic=default]]>
	</fieldset>
</form>

Form Wrapper:

[[!SimpleSearchForm?
    &tpl=Search Form
    &landing=21
    &ids=[[getReqParam? &name=`parent`]]
]]

Results Landing Page:

[[!SimpleSearch?
    &elementClass=modSnippet
    &ids=[[!getReqParam? &name=parent]]
    &includeTVs=1
    &containerTpl=Search Result Container
    &tpl=Search Result Row
    &pageTpl=Search Result Link
    &exclude=1,68
]]
[[!+results:notempty=<p class="filterResult">[[+results_found]]</p>]]

When you say return nothing, are you talking about your PDO call? As in, it’s not returning any options. Also, when you use the parameter resources, PdoResources will only search those resources, you may be better moving the 1,2,3 into parents parameter instead.

By “nothing” I mean no search results are displayed on the landing page even when the search query matches known resources. Only when searching the entire site 0 does it work as expected.

I previously tried moving the ids (1,2,3) to parents but that doesn’t work.

I can’t detect anything that is clearly wrong, so maybe you can narrow down the point where it fails with some debugging:

  • When you do a search, do you see the GET-parameter ?parent=2 in the URL with the right value?
  • Is the extra getReqParam installed? When you put this line Request-Parameter = [[!getReqParam? &name=`parent`]] in the landing page, do you see that the right value is outputted?
  • Does it work with a simpler basic setup like this:
[[!SimpleSearchForm?
    &tpl=`Search Form`
]]

<h2>Results</h2>
[[!SimpleSearch?
    &ids=`[[!getReqParam? &name=`parent`]]`
]]
  • Does it work when you hardcode a value for the property &ids?
[[!SimpleSearch?
    &ids=`2`
]]

In order:

Point 1: Yes
Point 2: Yes
Point 3: No
Point 4: No

That a hardcoded value for &ids doesn’t work is astonishing!

[[!SimpleSearch? &ids=`2`]]

Does a resource with this ID (here 2) exist? Does the resource have published child-resources with the search-value? Is the checkbox Searchable set in the child-resources?

If you just put this line in a new resource and then view this resource and add a GET-parameter ?search=test to the URL, is there really no output?

The hardcoded id seemingly has no effect whatsoever as it still returns no matching results.

Yes, ids 2,3,4 exist and are published and searchable. And yes, the child resources are published and searchable. Even searching for a resource by its exact pagetitle returns nothing. Why it works perfectly when searching the entire site (Option 1 in the search picker) and not a specific folder is very odd to me.

The only other thing I can think of is that I’m using the SEO Tab Extra which has a setting to “Include this page in internal search results?” which I have enabled by default so it should not be an issue but I will uninstall it and retry.

You could disable the plugin rather than uninstall it. That way it won’t execute but you don’t need to remove it if it happens to be the culprit.

When you test it with the line

[[!SimpleSearch]]

without any properties, can you then search for child-resources of the resources 2, 3 and 4?

Do you have multiple contexts?

Ok, it seems to be working for now (still testing).

A custom propertyset (not shown in the above code) appears to be the problem. Once I removed the pset the other folders (2,3,4) now return matching results.

Thank you to all.

1 Like