Forum

Thread tagged as: Question, Problem, Third-party

Perch Search

Hi,

So I'm trying to find a way to make the perch search a little broader.

Currently, if a user searches "Egypt", for example, this will ignore any result with the word "Egyptian". From the looks of the debug, Perch makes used of MATCH/AGAINST MySQL Queries - is it possible to introduce any wildcarding?

I looked into MATCH/AGAINST and found that you can apparently use wildcards like "Egypt*" (working a little like a LIKE function, although the wildcard can't go at the front). This doesn't work with Perch, so I wondered if there is a simple way (already built in) to get it to do what I want? If not, are there any 3rd party (don't mind if they aren't free) extensions or plugins for website search that Perch is compatible with? As exact keyword searches are a bit limited.

Thanks for any help!

Matthew Lymer

Matthew Lymer 1 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I think I'd personally use something like Elastic Search for any site where search was a big priority. I don't know of any third party plugins, but it would certainly be possible to implement something like that.

Ok, so I'm guessing I would then need to hook an elasticsearch server to Perch? Is there any straightforward way of hooking all database operations in perch that you know of?

(Failing that, I could just have a cron job regularly index the perch database, creating an elastic search database to be searched, just wondered if there was a simpler way)

Drew McLellan

Drew McLellan 2638 points
Perch Support

There's an event that gets fired when content is indexed for search. I believe you should be able to register a listener for that and then stash the content in an external system.

Ah, now that sounds like a good place to start!

I'll see if I can find said event (if you know what it's called or where it's defined, that may help too).

Thanks!

Drew McLellan

Drew McLellan 2638 points
Perch Support

region.index is probably the place to start.

Thanks Drew,

I've got together something that works, using the index tables of the database, and it seems perfectly fast enough (not tested on a large index, but thankfully this is for a fairly small website).

Regards,

Hi Matthew,

Sorry to use this thread but seemed the only way to contact you. I found this old forum post of yours where you say you managed to allow members to upload images and handle those images using some custom code:

https://forum.grabaperch.com/forum/11-18-2015-members-app-upload-fileimage

I was wondering if you'd be kind enough to share the code that you came up with for this, if you still have it?

Thanks in advance for any help you may be able to offer.

Hi Stephen,

Unfortunately, I can't share the code directly - as my client wouldn't allow this. However, I can share the concept of what I did:

  • Images are uploaded using a typical HTML input field, but when saved, they are given a name that matches the username of the current logged in user.

So, for example: Step 1) An HTML upload allows image upload

<form action="/upload.php" method="POST">
     <input id="logo" name="logo" type="file" required="required" />
</form

Step 2) Once the form is submitted, the upload.php page should contain something like:

if(isset($_FILES['logo'])){
     $userHash = sha1(perch_member_get('email') . $salt);
     move_uploaded_file($_FILES["logo"]["tmp_name"], $_SERVER['DOCUMENT_ROOT'] . "/logos/" . $userHash . ".png");
     //Image processing code, e.g. using ghostscript or imagick
}

Now, this is quite a simple version of the concept I went with (maybe worth fully assessing the security of this, particularly if logos access should be sensitive).

Thanks Matthew. Did you have this as part of the member sign up form or a separate form after they had signed up?

Hi Stephen,

Both actually. In my setup, users COULD provide a logo, but didn't have to.

I then had an area to upload (or replace existing) logo on the users settings page (as for this example, a logo was required to use the system fully).

Regards,