Jump to content

SimpleSearch module


froot
 Share

Recommended Posts

I wrote this search module: https://github.com/dtjngl/simpleSearch

It works OK so far, however I don't know why I cannot uninstall it. When I uninstall it, it keeps reinstalling. Is that issue to be found in the module? Cause I do have locations in my website template files where I initiate this module but that shouldn't matter because it reinstalls (or doesn't uninstall) while still on the modules overview page in admin. Also no mentions of it on ready.php etc.

Thanks for help! 

  • Like 1
Link to comment
Share on other sites

6 hours ago, fruid said:

Cause I do have locations in my website template files where I initiate this module but that shouldn't matter because it reinstalls (or doesn't uninstall) while still on the modules overview page in admin

Or maybe it does? "get" does install and initialize the module, if available https://processwire.com/api/ref/modules/get/

Is it possible a visit occured right after you tried to uninstall?

  • Like 1
Link to comment
Share on other sites

22 hours ago, fruid said:

Is that issue to be found in the module?

After a quick glance, I don't think so. Have you tried writing into the PW log from ___install and ___uninstall? This should at least tell you whether uninstall+install happen. In the later case, you should also see the page request that triggers the re-installation. Just to make sure: you have $config->debug enabled so you don't miss any warnings, right?

  • Like 1
Link to comment
Share on other sites

yes I'm in debug and have tracy.

When I uninstall, I can confirm that what ever I log from inside the __uninstall() method doesn't get logged.

That is strange.

Also, in the module I defined some hooks that get triggered when saving a template. Might that be the culprit? It still makes no sense to me since when I'm uninstalling the module, I'm not on and am not editing a template.

public function ready() {
	$this->addHookAfter("ProcessTemplate::buildEditForm", $this, 'addSimpleSearchCategoryField');
	$this->addHookBefore("ProcessTemplate::executeSave", $this, 'saveSimpleSearchCategoryFieldValue');
}
Link to comment
Share on other sites

I really don't think the problem is within the module code. Are there any messages when you do a Modules -> Refresh? Do you have another module active that accesses simpleSearch?

Additional idea: a debug_backtrace from within the constructor might be able to shed some light on it if it's really a case of the module being blocked from uninstall because it's in use.

Link to comment
Share on other sites

You could try to delete the row of your module in the "modules" database table. That would mean that the module is uninstalled.

Then you could check if the module get's installed automatically on the next page load or modules refresh. If it get's installed you could add something like this to your install() method of the module:

bd(debug_backtrace());
die();

In that backtrace you should then see what is triggering the installation of the module.

  • Like 1
Link to comment
Share on other sites

I actually found this in the modules.txt log file:

2023-12-21 11:36:09    admin   https://mysite.ddev.site/admin/module/edit?name=SimpleSearch&collapse_info=1  Uninstalled module 'SimpleSearch'
2023-12-21 11:36:10    admin   https://mysite.ddev.site/favicon.ico  Installed module 'SimpleSearch'

Super strange! I removed the favicon.ico links in the head tag, removed the favicon icons, cleared cache, refreshed modules, cleared compiled files, issue remains

Will try this now:

On 12/19/2023 at 8:54 PM, bernhard said:

You could try to delete the row of your module in the "modules" database table. That would mean that the module is uninstalled.

Then you could check if the module get's installed automatically on the next page load or modules refresh. If it get's installed you could add something like this to your install() method of the module:

bd(debug_backtrace());
die();

 

EDIT: I just tried this and Tracy doesn't bd-log anything from inside the install() method nor the uninstall() method, I mean not even this gets logged:

bd('install');
 

So strange!

Link to comment
Share on other sites

The module still needs quite some improvement. One issue that needs attendance is the following.

I build a selector and select a page array from the database.

$selector = $this->createSelector($this->q, $category);
bd($selector);
$unfilteredMatches = $this->pages("$selector, start=0, limit=99999");

As discussed in this thread it's (so far) impossible to select pages based on language specific field values. So the query looks through the field values in all languages for the search term.

Since this is not what I want, instead I want the query to only match the fields values of the current user language, I do another loop and within that loop, with the method buildSnippets() I create the snippets for the markup. If this returns null (this is now language specific) I sort out the page entirely.

$strippedFieldValue = strip_tags($fieldValue);
// Find the position of the search term in the field value
$position = stripos($strippedFieldValue, $searchTerm);
    
// If the search term is not found, return an empty string
if ($position === false) {
	return false;
}

So basically I'm selecting once via selector and then narrow it down with a loop. 

That works for a one-term search query or an exact phrase, but it makes sense that It won't and doesn't work when the search operand is on the fancier side as listed here:

https://processwire.com/docs/selectors/operators/#contains

What would you suggest? Is my approach so far sensible? Should I hard-code a different loop condition for each of the fancy search operands? I want to give the module-user (not enduser but admin user) the option to adjust the search operand in the module's settings.

Thanks for help!  

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...