Jump to content

Search index not looking for data in repeaterMatrix


cboetens
 Share

Recommended Posts

Hi guys

So I'm building a little search index for a client with this recipe I've found on the ProcessWire Recipes website (more info: https://processwire-recipes.com/recipes/set-up-search-index-with-fieldtypecache/)

I've followed the exact steps in the recipe and the script appears to be working, except for Profields: Repeater Matrix. 🙄

This is the code I've got so far:

<?php include('includes/header.php') ?>
<?php 
	$q = $sanitizer->selectorValue($input->get->q);


	if($q) {
	    $results = $pages->find('search_cache%='. $q);
    } else {
        $results = new stdClass();
        $results->count = 0;
    }

?>

<section class="partners-block-consul mb-5">
	<div class="container">
		<div class="row">
			<div class="col-sm-10 offset-sm-1">
				<div class="partners-head sec-p-lg">
					<?php if($page->headline) { ?>
						<h1 class="highlight"><?= $page->headline ?></h1>
					<?php } ?>
					<div class="cms text-left">
						<p>Er werden <?= $results->count ?> resultaten gevonden.</p>
						<?php if($results->count > 0){ ?>
							<ul>
								<?php
								foreach($results as $result){

									if($result->template->name == "faq_item") {
										$category = $pages->get("id=".$result->faq_category);
										$parent_template = $category->rootParent();

										?>
										<li><?= $result->title ?> - <a href="<?= $parent_template->url . $category->name . "/"; ?>" title="<?= $result->title ?>"><?= $labels->read_more ?></a></li>
										<?php
									} elseif($result->template->name == "faq_category") {
											$parent_template = $result->rootParent();

											$faqCategoryUrl = $parent_template->url . $result->name . "/";

											?>
											<li><?= $result->title ?> - <a href="<?= $faqCategoryUrl; ?>" title="<?= $result->title ?>"><?= $labels->read_more ?></a></li>
											<?php
									} else {
										?>
										<li><?= $result->title ?> - <a href="<?= $result->url; ?>" title="<?= $result->title ?>"><?= $labels->read_more ?></a></li>
										<?php
									}

								?>
								<?php } ?>
							</ul>
						<?php } ?>
					</div>
				</div>
			</div>
		</div>
	</div>
</section>
<?php include('includes/cta.php'); ?>
<?php include('includes/footer.php'); ?>

In the ProcessWire admin the "search_cache" field is being build as follows (see image 1).

255705076_Schermafbeelding2020-01-20om16_44_08.thumb.png.dcad3548b8eb775f1c1c1b4fe13fb4a2.png

920525770_Schermafbeelding2020-01-20om16_46_25.thumb.png.5c344b23be95f2d95b5bbfe12af41d1f.png

Then, the field 'search_cache' is being used on the following templates (see image 2 and 3). So, let's say I'm searching the word 'kinderen', which should get a hit on the template 'Kind', the script isn't returning this page as one of the hits (the result should return 'migraine').

 

893147765_Schermafbeelding2020-01-20om16_53_43.thumb.png.bae9682d6b5bd1ddac33b2c85ff3b8d3.png

If someone has any idea why the script is not looking for the data that is being put in the field "Profields: Repeater Matrix", he/ she would be my personal hero! 🤗

Greetings

Cédric

 

Schermafbeelding 2020-01-20 om 16.46.34.png

Schermafbeelding 2020-01-20 om 16.52.24.png

Link to comment
Share on other sites

I have no idea. I just tried it here as well - RM fields get ignored.

Ryan stated a while back (~ 5 yrs ago) that the whole concept of this field-type was outdated, and wasn't delivering the performance advantages etc. he initially had in mind. That's also the reason it eventually got kicked out the core. I guess this field-type is much older than some newer field-types like repeater matrix, so it never got updated to accomodate them.

It's not too hard though to re-build the same basic functionality though with a regular text field and a hook that on page-save collects all text-based fields in your template(s) and saves it to that field.

What you could also try is using fieldtype(s) instead of fields: https://processwire.com/blog/posts/processwire-3.0.91-core-updates/

This won't help with caching though, just keep your selector string a bit more readable...

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

×
×
  • Create New...