Jump to content

SearchEngine


teppo

Recommended Posts

On 10/14/2021 at 9:47 PM, tires said:

I chose the Operator:
~=
(i.E. All given words appear in compared value, in any order. Matches whole words. Uses “fulltext” index.)

But if i enter "everything 2021" i am not finding the page with the titel "everything is great in 2021".

Try this as Operator:

~%= or ~*=

I use this on all my sites with the AjaxSearch module, but it should work here as well.

Here you can find Ryan's blogpost: https://processwire.com/blog/posts/pw-3.0.160/

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Hi

I get a fatal error when I click on "Debugger" in module settings page.

Return value of SearchEngine\Debugger::getWords() must be of the type array, null returned

File: .../modules/SearchEngine/lib/Debugger.php:599

Sorry I just update the module and I resolved it with the 0.30.3 version.

have a nice day

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

I’ve just set up searching with SearchEngine with basically all of the default options, and I’m really impressed! I‘ve turned on group-by-template, and it’s almost exactly what I want!

The template-named filtering buttons are terrific and intuitive.... I find that I’d like to render them as *plurals*, though, where the template names are *singular*. For example, I have a template *Person* that I would like to see as *People*, and another template *Journal* that I’d like to see as *Journals*.

Is there a built-in way to do this? If not, does anyone have any suggestions as to how I might go about implementing this.... Just guidance as to where I might put a switch/case statement would be acceptable, though I wouldn’t be surprised if there was a more elegant solution.

Thanks!

Link to comment
Share on other sites

Well, it looks like I should do something with `tabs_tab` — but I’m really not sure what. Is this something I can change in site->config.php? I don’t see how....

Link to comment
Share on other sites

 @gornycreative - if I understand correctly, this should work.

$searchEngine->addHookAfter('Renderer::renderTabLabel', function($event) use($types) {
    $event->return = $event->return . 's';
});

I was modifying the tabs a little more via a $types associative array, which you can see here. Just for fun I also included the hook I used to add images to the results.

Spoiler

$types = array(
    'All' => 'All',
    'Staff' => 'People',
    'Publication' => 'Publications',
    'Media' => 'Media Library',
    'Blog Post' => 'Blog Posts',
    'Enewsletter Article' => 'Enewsletter Articles',
    'Project' => 'Projects',
    'Education' => 'Education',
    'Education Program' => 'Programs',
    'Education Course' => 'Courses',
    'Page' => 'Pages'
);

$searchEngine = $modules->get('SearchEngine');

// cleanup for weird links like
// https://mysite.com/search/?q=test&t=blog_post>previous blog posts<%2Fa>).<%2Fp> <p><img title%3D
$t = $input->get('t');
$templateLabel = '';

if($t != '') {
    $template = $templates->get($t);
    if($template) {
        $templateLabel = $template->label;
    }
    else {
        // remove everything after (and including) first non-alphanumeric character
        preg_match("/[a-zA-Z0-9-_]+/", $t, $match);
        $t = $match[0];
        $template = $templates->get($t);
        if($template) {
            $templateLabel = $template->label;
        }
    }
}

if($t != '' && $t != $input->get('t')) {
    $session->redirect($page->url.'?q='.$input->get('q').'&t='.$t);
}
elseif($t != '' && !isset($types[$templateLabel])) {
    $session->redirect($page->url.'?q='.$input->get('q'));
}

$searchEngine->addHookAfter('Renderer::renderTabLabel', function($event) use($types) {
    $event->return = $types[$event->return];
});


$searchEngine->addHookAfter('Renderer::renderResult', function($event) {
    $p = $event->arguments[0];
    $image = $p->getunFormatted('pdf_images|image|images|video_images')->first();
    if($image) {
        $thumb = $image->size(0, 260, array('upscaling' => false));
        $event->return = '
        <div class="row">
            <div class="small-12 medium-4 large-5 xlarge-4 xxlarge-3 columns teaser__image">
                <a href="'.$p->url.'">
                    <img style="max-height: 300px" src = "'.$thumb->url.'" />
                </a>
            </div>
            <div class="small-12 medium-8 large-7 xlarge-8 xxlarge-9 columns teaser__content">
            ' . $event->return . '
        </div>';
    }
});

In the end I actually stopped using the built in tabs feature because even though it's really awesome, it doesn't work with multiple operators like: *=~= so I built up the tabs manually and now I can even change the operator if the user has wrapped something in double quotes to make it an exact match.

  • Like 1
Link to comment
Share on other sites

@adrian you answered @ErikMH tab question...

I was asking about the auto_desc being blank for partial word matches on the terms - but I can also see how this might get sticky unless you limited the generation to a single/first appearance. There could be dozens of places where a term partially matches on a page.

Link to comment
Share on other sites

On 7/19/2021 at 5:24 PM, gornycreative said:

This has been great. I just wanted to confirm one thing I noticed which is that _auto_desc doesn't seem to highlight/load a summary on partial word matches, although the search itself picks them up.

So for example if I search for 'business' using a partial match operator, any article search_index that includes the whole word 'business' will create a summary with the word 'business' marked... and results will show up where businesses and businessmen are in the index, but no summary with a highlighted partial word appears. The summary for these entries is blank.

Is this the intended behavior?

Sorry for missing this question — and no, it doesn't seem like intended behaviour.

I've made some adjustments to the latest version, 0.30.4, that should make things better in this regard. At least it helped with these exact terms (business/businesses/businessmen) in my limited tests. Please let me know if this doesn't work, or if it makes things somehow worse, though 🙂

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
×
×
  • Create New...