Help or examples needed for FullTextSearch form

I’m trying to implement the FullTextSearch extra. Unlike SimpleSearch, there is no form snippet. I’m stuck on working out how to link the search form to the FullTextSearch snippet call. Anyone have a working example they could post here?

The examples on GitHub suggest no specific form is needed:

By default it looks for a search parameter in the url or POST so any form with a text input with name search should work.

Ah, thank you! I had name=“search” on the form tag instead of the input tag. (This board has no :headdesk: emoji? Weird.)

Have it working now… sort of. But,
If a term is searched the list returned looks to be correct. But if NO term is searched (page loaded w/out a URL param) the snippet is returning ALL the pages on the site. I have to read up on the snippet properties. :grimacing:

Do you have &parents=`-1` on the getResources call? Looks like that would make sure only the specific resources are returned and your search page doesn’t turn into a sitemap :grimacing: :sweat_smile:

Yes, thanks again. I think the problem may be that I’m using pdoResources… Will test later with gR. When I have -1 set I get a list of all pages that are set in the manager to searchable, no matter whether there is a term searched or not. When I use 0 I get a complete sitemap, again (seems like) whether a term is searched or not.

I am testing the results list by removing the pdoresources call and sending the FTS snippet to a placeholder and simply displaying the placeholder. I’m seeing some unexpected results. For instance: I have intentionally seeded a page with words that do not occur anywhere else on the site. Searching for one of these words, you’d expect that one page would be returned. But 0 pages are returned. Searching for a word that is in 3 pages returns the 3 pages. Having read the docs I expected that terms that are common (above 50%) would be excluded, but this seems like the opposite is happening. :thinking:

Making some progress. There is a difference in the way getResources and pdoResources treat the relationship between &parents and &resources, and it becomes an issue when used with the FullTextSearch snippet. The FTS placeholder is used to pass the resources to the gR or pR &resources property. If the placeholder is empty (as in no search has occurred or no results) gR displays nothing but pR displays all the pages.

This is because:
gR – Use -1 to ignore parents when specifying _resources_to include. (If &resources property is set, but is empty, nothing displays.)
pR – If a parent id starts with a dash, it and its children are excluded from the query. (So -1 just excludes the resource and children with ID of 1. If &resources property is set, but is empty, the &parents property determines what to display. *see further details below)

So for the time being I’ve wrapped the pR call in a conditional to prevent it if the FTS placeholder is empty.
So in the search page:

[[!FullTextSearch? &toPlaceholder=`fts_results`]]
[[!+fts_results:is=``:then=`No Results`:else=`[[$fullTextSearch]]`]]

And in the fullTextSearch chunk:

[[!pdoResources?
    &parents=`0`
    &resources=`[[!+fts_results]]`
    &limit=`20`
    &includeContent=`1`
    &tpl=`search_results`
    &tplWrapper=`@INLINE <ul class="list-unstyled">[[+output]]</ul>`
]]

Still a mystery why my seeded words that only exist in one place on the site are not returned at all in results.

*A further mystery. Without the conditional output modifier on the placeholder:

  • If pdoResources &parents property is set to 0, all pages which are set to searchable are displayed if the FTS placeholder is empty.
  • If pdoResources &parents property is set to -1, all pages of the site, whether or not set to searchable are displayed if the FTS placeholder is empty. I have no idea why.

To debug you could try the following:

  • Check if the resource is indexed at all. Go to your database and look at the table modx_fts_content. Does a row with the content_id of your resource exist?
  • Does the field content_output of this row contain the seeded words?
  • Run the following SQL query. (Replace ‘my seeded words’ with your actual search term in both places.)
SELECT
	content_id,
	MATCH (content_output) AGAINST ('my seeded words' IN NATURAL LANGUAGE MODE) AS score
FROM modx_fts_content
WHERE MATCH (content_output) AGAINST ('my seeded words' IN NATURAL LANGUAGE MODE)
  • Do you get a result? Is the score of this result higher than the &scoreThreshold-property (1.0 by default)?
1 Like

Thank you, I had checked to see that everything was indexed as expected, but had no idea how to check the scores. I ran that query on many words and no single word searches had a score higher than 1.0. (One that was hyphenated did.) So, maybe the number of resources I have indexed is just too low at this point…?

One interesting thing is apparently MySQL full-text search doesn’t have the 50% of rows threshold with InnoDB tables.

I will try lowering the threshold to see how that effects the results. (And if that doesn’t help then maybe it’s back to SimpleSearch, but I love the simplicity of this snippet.)

Edit: I just re-indexed and now all the unexpected fields are gone from the index. Not sure how they could have been there in the first place since I have never changed the system setting indexFullRenderedOutput from the default of disabled.

I think I may have found a bug @sepiariver .
According to the github page, when the system setting indexFullRenderedOutput is disabled (which is the default, and mine is still set to No), then only the fields listed in the setting indexResourceFields should be indexed. The fields listed by default are pagetitle,longtitle,description,content. So in my index row I should only see the content of those fields, but the index contains the entire rendered page, (menu names, logo, footer, etc.).

Edit: I have re-indexed and now the unexpected fields are gone from the index. Not sure how they were there in the first place since I have never changed the setting indexFullRenderedOutput from the default of disabled.