Jump to content
cboetens

Search index not looking for data in repeaterMatrix

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

Share this post


Link to post
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...

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By stanoliver
      Hi! I tried to implement a simple site search like in the regular site profile by Ryan.
      http://demo.processwire.com/regular/
      I checked out the code on github but I could not make it work for my site. Probably because Ryan uses some advanced output strategy and uikit specific stuff which I don't use or understand.
      For my site I just use:
      - 1 template (name: templatetoparea.php) for the toparea of my site
      - 1 template (name: templatemainare.php) for the main content of my site
      - 1 template (name: templatefooterarea.php) for the footerarea of my site.
      Also I have prepared two empty templates:
      - 1 template (name: templatesearch.php) for the search itself
      - 1 template (name: templatelistsearch.php) for listing the search results
      May somebody could let me know how to implement a very basic site search like in the regular site profile without using any module or complicated output strategies.
      Two things would be a must have:
      - The search should work with standard repeaters (where most of my content lives)
      - The search results/hits should be listed and the search word(s) should have a yellow colored background (inline css is fine) 
    • By dandeckr
      Hello!
      I'm making my way through my first encounter with ProcessWire, and I'm very near the end of my tasks! I've searched Google, these forums, and for add-ons, but I haven't found any documentation or reference work for implementing boolean searching in the native CMS? Am I missing a thread, add-on, or docs that can point the way? I'm sure I'm not the first to have a need like this? Thanks in advance! 
    • By slave
      I would like to create a search form with a category selection.
      I do not get the selector, I need help
      my selector
      $katId = $pages->find("template=leftnav_kat, h1_h6_1%=$kat"); its ok
      $matches = $pages->find("template=site, has_parent=$katId"); its ok
      myresult this pages (templates = site):
      MedLab ML +2 °C bis +8 °C 41 Liter
      MedLab ML +2 °C bis +8 °C 41 Liter
      MedLab ML +2 °C bis +8 °C 45 Liter
      MedLab ML +2 °C bis +8 °C 82 Liter
      MedLab ML +2 °C bis +8 °C 82 Liter
      LabStar Sanguis +2 °C bis +6 °C 100 Liter
      MedLab ML +2 °C bis +8 °C 107 Liter
      LabStar Sanguis +2 °C bis +6 °C 100 Liter
      MedLab ML +2 °C bis +8 °C 82 Liter
      but I'm looking for a text in the template = site, this template has a field search_cache

      $katId = $pages->find("template=leftnav_kat, h1_h6_1%=$kat"); its ok
      $matches = $pages->find("template=site, has_parent=$katId, search_cache%=Industrie"); not work
      I need help
       
       
       

    • By TLT
      Hello, and thanks again for PW. The more I use it, the more I like it.
      I have a silly problem, and since I have tested several (bad) solutions, I come and ask for help. I think I'm just being thick there...
      Is there a relatively simple way to add an allowed character to the default search form's sanitizer ?
      FYI, I'm working on a dictionary in breton language (60k entries), and I must find a way to allow apostrophes in search input. (In breton language, "CH" and "C'H" are actually two different letters altogether).
      I must say I'm a bit confused by the sanitizer. On the regular search form, it appears three times. Once in the input field itself, and twice on the search template.
      I did read the sanitizer page and sanitizer class page, but I'm not sure to understand where to go from there. From what I understand, the
      $sanitizer->name methods would accept some extra allowed character, but I seem to have no luck in adding this to my template. Morevover, do I have to change any sanitizer call to a -> name one ?
      The sanitizer php core page includes an "allowedASCII" which seems very promising, but is there a way to override it ? Hooks ? (not used to them I'm affraid...)
      Morevover, the fact that i'm trying to implement the (') character worries my a bit. Can I escape it ? would something like '\'' do the trick ?
      Thank in advance to you, good men. The site building is reaching an end, and I am tired indeed. (you wouldn't believe the state of the initial DB I had to work from...)
    • By Tigro
      Hi guys,
      i want to create some search filters in the backend. The filters should display fields, which lie in a repeater group. Is it possible to display this in the search?
      Thanks for your Support!


×
×
  • Create New...