Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleSearch breaks website after server migration #54

Open
Lovehelmet opened this issue Oct 11, 2022 · 29 comments
Open

SimpleSearch breaks website after server migration #54

Lovehelmet opened this issue Oct 11, 2022 · 29 comments

Comments

@Lovehelmet
Copy link

  • MODx admin works as expected but no webpage renders, just get an error 500.
  • Uninstalling SimpleSearch fixes the issue and everything works fine.
  • Reinstalling SimpleSearch breaks the site again.

Now, I have a site developed locally that van't go live with a functional search.

@halftrainedharry
Copy link

What versions of MODX and SimpleSearch are you using? (There are at the moment 2 different versions of SimpleSearch for MODX 2.x and 3.x respectively.)
What's the PHP version? How does the webserver differ from you local setup?

Can you check the PHP error log to see what the exact error message is?

@Lovehelmet
Copy link
Author

Lovehelmet commented Oct 12, 2022 via email

@halftrainedharry
Copy link

Check the system setting "simplesearch.driver_class". Make sure the value is \SimpleSearch\Driver\SimpleSearchDriverBasic.


If this doesn't solve the problem then please check the PHP error log. An exact error message (where and why the error occurred) would help a lot to solve the issue.

If you are unsure where the PHP error log is located, take a look at the config file "php.ini". Probably the setting error_log. (Maybe also check the values of other settings like log_errors, display_errors, error_reporting.)

@Lovehelmet
Copy link
Author

Lovehelmet commented Oct 12, 2022 via email

@Lovehelmet
Copy link
Author

Lovehelmet commented Oct 13, 2022 via email

@halftrainedharry
Copy link

I don't quite understand what your setup is.

Do you show the search form on every page [[!SimpleSearchForm? &landing=`46`]] and then on page 46 you display the search results [[!SimpleSearch]]?

SimpleSearch should always search the whole website (all resources) unless you define a property like &ids in your snippet call.

@Lovehelmet
Copy link
Author

Lovehelmet commented Oct 13, 2022 via email

@halftrainedharry
Copy link

halftrainedharry commented Oct 13, 2022

it only finds theresulys page with id 46 from pages that is not subpages.

What is the value of the action attribute in your form? This should be the same for every page and subpage.

<form class="simplesearch-search-form" action="searchresultspage.html" method="get">

What is the value of the action attribute in your template chunk?

<form class="simplesearch-search-form" action="[[~[[+landing]]]]" method="[[+method]]">

@Lovehelmet
Copy link
Author

Lovehelmet commented Oct 13, 2022 via email

@halftrainedharry
Copy link

But what is the actual value that is shown in the source code for the action attribute on your subpage?

What is the "Resource Alias" of your search-results-page? (On the screenshot this page seems to be unpublished. It should be published to be publicly accessible.)

The id parameter in the form <input type="hidden" name="id" value="[[+landing]]" /> is irrelevant if friendly-urls are used (which seems to be the case).

@Lovehelmet
Copy link
Author

Lovehelmet commented Oct 13, 2022 via email

@Lovehelmet
Copy link
Author

Lovehelmet commented Oct 13, 2022 via email

@halftrainedharry
Copy link

And the rendered value in source code on every page when search is made is:
<form class="simplesearch-search-form" action="sökresultat/" method="get">

So when you submit the search form, there is a html-request to yourdomain.com/sökresultat/ on every page with a get parameter search for the search value.

Why wouldn't this work on a subpage? Maybe the <base> tag is wrong on your subpage?

On your screenshot above ("4 results found ...") why is there no sökresultat/ in the URL?

@Lovehelmet
Copy link
Author

Lovehelmet commented Oct 17, 2022

Well..
I've tried, tried and tried to make this work but feel like I'm at my wits end..
I'll try to explain this matter again and hope for a solution.

I have at setup on my localhost via latest MAMP 6.6.
MySQL 5.7.34
PHP 7.4.21
ModX 3.0.1-pl
SimpleSearch 3.0.0-alpha (standard setup, have not changed anything)

I've enabled Friendly URLs and every page has the same base URL
The search results page has the file name "Sökresultat", the resource alias "sokresultat" and the ID of "46".
This results page is published but hidden from menu and has the tag [[!SimpleSearch]] included in the content part of the page.

The SimpleSearch chunk "SearchForm" has the form:

<form class="simplesearch-search-form" action="[[~[[+landing]]]]" method="[[+method]]">
    <fieldset>
        <label for="[[+searchIndex]]">[[%simplesearch.search? &namespace=`simplesearch` &topic=`default`]]</label>
        <input type="search" name="[[+searchIndex]]" id="[[+searchIndex]]" value="[[+searchValue]]" />
        <input type="hidden" name="id" value="[[+landing]]" />
        <input type="submit" value="[[%simplesearch.search? &namespace=`simplesearch` &topic=`default`]]" />
    </fieldset>
</form>

No changes has been made to the snippets "SimpleSearch" or "SimpleSearchForm".

My search form has the code:

<form>
    <div class="row justify-content-center">
        <div class="col-lg-6 col-md-8">
            [[!SimpleSearchForm? &landing=`46`]]
        </div>
     </div>
</form>

If search for the term "bygg" is made from the start page (http://localhost/bootstrap/), the search results are displayed on the results page as expected.
The URL shown in this case is: http://localhost/bootstrap/?search=bygg&id=46
The rendered form code on the results page is:

<form class="simplesearch-search-form" action="sokresultat/" method="get">
    <fieldset>
        <label for="search">Sök</label>
        <input type="text" name="search" id="search" value="bygg" />
        <input type="hidden" name="id" value="46" />
        <input type="submit" value="Sök" />
    </fieldset>
</form>

If search is made from another page, for example: http://localhost/bootstrap/om-oss/, the search is made but SimpleSearch seems to look for the results page in the wrong place and the results page is not displayed with the results.
The URL shown in this case is: http://localhost/bootstrap/om-oss/?search=bygg&id=46

The rendered form code on this page is the same as above:

<form class="simplesearch-search-form" action="sokresultat/" method="get">
    <fieldset>
        <label for="search">Sök</label>
        <input type="text" name="search" id="search" value="bygg" />
        <input type="hidden" name="id" value="46" />
        <input type="submit" value="Sök" />
    </fieldset>
</form>

SimpleSearch makes the search but tries to render the results on the "om-oss" page though with the right id "46".
So it seems that SimpleSearch does not always look for the resource with, in this case, the id"46" relatively to the root, but to the page the search is made from and THEN add "?search=bygg&id=46" to the end of the URL.

Hence search made from root of site renders the search results via the intended resource with ID "46".
Example: http://localhost/bootstrap/?search=bygg&id=46

Search made from any other page tries to render the search results on the page search i made from via the intended resource with ID "46".
Example: http://localhost/bootstrap/om-oss/?search=bygg&id=46

I can't seem to figure out a solution to this problem.
I need the search to render the search results using the resource "sokresultat/" with id "46" from which ever page the search is made from and I desperately need help with this.

If you'd like, I could make a migration file zip and mail a link to file via Sprend so you can install the whole site and see for yourself.
ANY help to solve this problem asap is deeply appreciated.

//Bo

@halftrainedharry
Copy link

Something is wrong with your friendly URLs.

When you navigate in the manager to the "Sökresultat" resource and click the "View" button (in the top right corner), what is the URL? It should be http://localhost/bootstrap/sokresultat (or maybe http://localhost/bootstrap/sokresultat.html).

Now if you manually add a "search" parameter to the URL (http://localhost/bootstrap/sokresultat?search=test) you should see the search results. This is all the search form has to do. Navigate to the "Sökresultat" page and provide a search string.

If nothing else works, maybe try hard-coding the "Sökresultat" URL in the search form.

If the URL of the "Sökresultat" is wrong, check the database table modx_site_content (columns "uri" and "alias") or try "Manage" -> "Clear Cache" -> "Refresh URIs".


The URL shown in this case is: http://localhost/bootstrap/?search=bygg&id=46

This URL is wrong. It should be http://localhost/bootstrap/sokresultat?search=bygg (or http://localhost/bootstrap/sokresultat?search=bygg&id=46)

The fact that it works is more a coincidence. When friendly URLs are not enabled, the URL of a page is http://localhost/bootstrap/index.php?id=46 (http://localhost/bootstrap?id=46 also works because index.php is the default file).

When friendly URLs are enabled the id parameter is generally ignored (?id=46), but it is still possible to request a page per id ( http://localhost/bootstrap/index.php?id=46) unless the system setting request_method_strict is set to Yes.

But you can't call http://localhost/bootstrap/om-oss/?id=46. There exists no index.php file in an om-oss folder! om-oss is used to load the corresponding resource and ?id=46 is ignored.

@Lovehelmet
Copy link
Author

Lovehelmet commented Oct 17, 2022 via email

@halftrainedharry
Copy link

Can you give me an example of how hard coding the "Sökresultat" URL in the search form would look like in the form below?

Just add the URL to the action attribute
<form class="simplesearch-search-form" action="http://localhost/bootstrap/sokresultat/" method="[[+method]]">

Or maybe this works as well:
<form class="simplesearch-search-form" action="[[~[[+landing]]? &scheme=`full`]]" method="[[+method]]">
(Using a different URL scheme: https://docs.modx.com/3.x/en/building-sites/settings/link_tag_scheme)

@Lovehelmet
Copy link
Author

Tried both:

<form class="simplesearch-search-form" action="http://localhost/bootstrap/sokresultat/" method="[[+method]]">
    <fieldset>
        <label for="[[+searchIndex]]">[[%simplesearch.search? &namespace=`simplesearch` &topic=`default`]]</label>
        <input type="search" name="[[+searchIndex]]" id="[[+searchIndex]]" value="[[+searchValue]]" />
        <input type="hidden" name="id" value="[[+landing]]" />
        <input type="submit" value="[[%simplesearch.search? &namespace=`simplesearch` &topic=`default`]]" />
    </fieldset>
</form>

And:

<form class="simplesearch-search-form" action="[[~[[+landing]]? &scheme=`full`]]" method="[[+method]]">
    <fieldset>
        <label for="[[+searchIndex]]">[[%simplesearch.search? &namespace=`simplesearch` &topic=`default`]]</label>
        <input type="search" name="[[+searchIndex]]" id="[[+searchIndex]]" value="[[+searchValue]]" />
        <input type="hidden" name="id" value="[[+landing]]" />
        <input type="submit" value="[[%simplesearch.search? &namespace=`simplesearch` &topic=`default`]]" />

    </fieldset>
</form>

Makes no difference at all so same disapointing results as before, only on start page and if I make a search from the results page rendered from search made on start page works...

Else is: http://localhost/bootstrap/byggtjanster/snickeri/?search=bygg&id=46 as an example.

@halftrainedharry
Copy link

I don't get it!

If an absolute URL is in the form (action="http://localhost/bootstrap/sokresultat/") and this URL is correct (because it works when you manually enter it into the address bar of the browser), why isn't this URL called? There is no MODX involved in this! This is basic HTML!

Are you sure you used the changed search-form-chunk?

If you add this directly into the page content, does that work?

<form class="simplesearch-search-form" action="http://localhost/bootstrap/sokresultat/" method="get">
    <fieldset>
        <input type="search" name="search" id="search" value="bygg" />
        <input type="submit" value="Search" />
    </fieldset>
</form>

Does a simple link tag work?

<a href="http://localhost/bootstrap/sokresultat/?search=bygg">Search Test</a>

@Lovehelmet
Copy link
Author

Both adding the form manually to a page and adding the link-tag works.
http://localhost/bootstrap/sokresultat/?search=bygg

As you can see the code is also in the "SearchForm" chunk, but that affects nothing.
Seames like nothing I change in this chunk affects the results..

Skärmavbild 2022-10-17 kl  11 39 52

@halftrainedharry
Copy link

halftrainedharry commented Oct 17, 2022

Duplicate the chunk, give it another name (e.g. "mySearchForm") and then add a &tpl property to the snippet call.

[[!SimpleSearchForm? &landing=`46` &tpl=`mySearchForm`]]

@Lovehelmet
Copy link
Author

Did that and tried 3 different ways in new chunk:

<form class="simplesearch-search-form" action="[[~[[+landing]]]]" method="[[+method]]">
    <fieldset>
        <label for="[[+searchIndex]]">[[%simplesearch.search? &namespace=`simplesearch` &topic=`default`]]</label>

        <input type="search" name="[[+searchIndex]]" id="[[+searchIndex]]" value="[[+searchValue]]" />
        <input type="hidden" name="id" value="[[+landing]]" />

        <input type="submit" value="[[%simplesearch.search? &namespace=`simplesearch` &topic=`default`]]" />
 
    </fieldset>
</form>
<form class="simplesearch-search-form" action="http://localhost/bootstrap/sokresultat/" method="get">
    <fieldset>
        <label for="[[+searchIndex]]">[[%simplesearch.search? &namespace=`simplesearch` &topic=`default`]]</label>

        <input type="search" name="[[+searchIndex]]" id="[[+searchIndex]]" value="[[+searchValue]]" />
        <input type="hidden" name="id" value="[[+landing]]" />

        <input type="submit" value="[[%simplesearch.search? &namespace=`simplesearch` &topic=`default`]]" />
 
    </fieldset>
</form>
<form class="simplesearch-search-form" action="[[~[[+landing]]? &scheme=`full`]]" method="[[+method]]">
    <fieldset>
        <label for="[[+searchIndex]]">[[%simplesearch.search? &namespace=`simplesearch` &topic=`default`]]</label>

        <input type="search" name="[[+searchIndex]]" id="[[+searchIndex]]" value="[[+searchValue]]" />
        <input type="hidden" name="id" value="[[+landing]]" />

        <input type="submit" value="[[%simplesearch.search? &namespace=`simplesearch` &topic=`default`]]" />
 
    </fieldset>
</form>

So when I either search from the index ro add the tag-link or your search form directly to a page it renders results and URL is: http://localhost/bootstrap/sokresultat/?search=bygg

When I make a search from any other page there is no results and the URL is: http://localhost/bootstrap/om-oss/?search=bygg&id=46

Skärmavbild 2022-10-17 kl  12 00 15
Skärmavbild 2022-10-17 kl  12 00 39

@Lovehelmet
Copy link
Author

As I see it there is only one difference:
It works on start page and from any page where form or link tag is manually implemented directly on the page.
It does not work from the search form chunk that I've linked in to every page via the page template [[$Search-Logo-left]]

@halftrainedharry
Copy link

So what is the difference between the hard-coded form

<form class="simplesearch-search-form" action="http://localhost/bootstrap/sokresultat/" method="get">
    <fieldset>
        <input type="search" name="search" id="search" value="" />
        <input type="submit" value="Search" />
    </fieldset>
</form>

and the output from "mySearchForm"?

Maybe the id parameter is the problem (although it shouldn't be). Try deleting this line in the chunk:
<input type="hidden" name="id" value="[[+landing]]" />

or just put the hard-coded form in a chunk and use that (and don't use SimpleSearchForm at all).

@Lovehelmet
Copy link
Author

The output from "mySearchForm" when using standard setup is:

<form class="simplesearch-search-form" action="sokresultat/" method="get">
  <fieldset>
   <label for="search">Sök</label>  
   <input type="search" name="search" id="search" value="bygg" />
   <input type="hidden" name="id" value="46" />  
   <input type="submit" value="Sök" />  
   </fieldset>
 </form>

When using alternativ 2 the output is:

<form class="simplesearch-search-form" action="http://localhost/bootstrap/sokresultat/" method="get">
    <fieldset>
        <label for="search">Sök</label>
        <input type="search" name="search" id="search" value="bygg" />
        <input type="hidden" name="id" value="46" />
        <input type="submit" value="Sök" />
    </fieldset>
</form>

When using alternativ 3 the output is:

<form class="simplesearch-search-form" action="http://localhost/bootstrap/sokresultat/" method="get">
    <fieldset>
        <label for="search">Sök</label>

        <input type="search" name="search" id="search" value="bygg" />
        <input type="hidden" name="id" value="46" />

        <input type="submit" value="Sök" />
 
    </fieldset>
</form>

Tried deleting the line:
<input type="hidden" name="id" value="[[+landing]]" />
No change

When replacing standard form in mySearchForm chunk with:

<form class="simplesearch-search-form" action="http://localhost/bootstrap/sokresultat/" method="get">
    <fieldset>
        <input type="search" name="search" id="search" value="" />
        <input type="submit" value="Search" />
    </fieldset>
</form>

Nothing happens, though it works when inserted directly on the page.

So, for example I've put both the form and the tag-link directly on a certain page and the search results page shows.
When making the search from the form linked in via the menu on the same page it does not.

@halftrainedharry
Copy link

Is there any Javascript code on your page that may interfere?
Maybe some code that rewrites links in the menu and by accident also changes the search form?

@Lovehelmet
Copy link
Author

Well, there are som scripts but none of them rewrites links in any way.
Also I can't see any difference between linked in form in menu and search code inserted directly on the page as both forms renders when page loads and therefore are actually on the rendered page before search is made in both cases.

I'm really mindf**d by this issue as I really can't figure out a working solution and delivery of webpage is delayed.. :(
But like I said before, I can mail a link to a migration folder to you so you can download, set it up and see for yourself if you want.

@halftrainedharry
Copy link

But like I said before, I can mail a link to a migration folder to you so you can download, set it up and see for yourself if you want.

No, I don't want that.
In my opinion this is a frontend issue. So if you have a publicly accessible version of the site I can take a look at it.


And maybe (temporarily) disable javascript in the browser, just to make sure that no javascript code interferes.

@Lovehelmet
Copy link
Author

Lovehelmet commented Oct 17, 2022

I've "solved" the matter by removing the search form from linked in slide-in modal in main menu and creating a search page with the form directly on that page. Not as elegant but it works.
Thanks for trying to help and sorry for wasting your time.
Regards,
//Bo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants