Possible to search for pages based on collection ID?
Permalink
Hey, all.
I'm using c5 to manage a knowledge base for my company. My manager would like for us to use the automatically assigned collection ID (cID) as a sort of tracking number for our procedural documents - a shorthand way of referring users to a particular procedure so one of our SMEs can tell someone "Go check out procedure 1338" instead of saying "Go check out the Network Device - Widget Poll Failed to Return Data within Time Threshold procedure."
I've been able to use a PHP code block to add this information to the page itself with the following:
Unfortunately, however, this number isn't searchable in any way that I can find. Does anyone know of any ways to search based on cID or possibly a way for me to create searchable content in the page without having to manually type in the cID for the page each time a document is created?
Thanks,
John
I'm using c5 to manage a knowledge base for my company. My manager would like for us to use the automatically assigned collection ID (cID) as a sort of tracking number for our procedural documents - a shorthand way of referring users to a particular procedure so one of our SMEs can tell someone "Go check out procedure 1338" instead of saying "Go check out the Network Device - Widget Poll Failed to Return Data within Time Threshold procedure."
I've been able to use a PHP code block to add this information to the page itself with the following:
<?php $page = Page::getCurrentPage(); $collectionID = $page->getCollectionID(); echo "<p><b>PROCEDURE $collectionID</b></p>"; ?>
Unfortunately, however, this number isn't searchable in any way that I can find. Does anyone know of any ways to search based on cID or possibly a way for me to create searchable content in the page without having to manually type in the cID for the page each time a document is created?
Thanks,
John
Hi, hutman.
I'm a tech writer by trade, so let me double-check your instructions, as my php knowledge and understanding of the concrete structure aren't expert-level by any stretch of the imagination.
I found a file called PageList.php in the /concrete/src/Page directory, and in that file, there was a section that looks like the following:
So if I understand this properly, I need to create an application/src/Page directory and create the PageList.php file there. And then in the section I posted above, I need to add the line you indicated. That way, I'm not overwriting core files, but I'm still adding the functionality in the right location.
Is that close to right? And this would allow my users to do a search on, for example, "883" and it would return the "[site]/index.php?cID=883" page as a result?
I'm a tech writer by trade, so let me double-check your instructions, as my php knowledge and understanding of the concrete structure aren't expert-level by any stretch of the imagination.
I found a file called PageList.php in the /concrete/src/Page directory, and in that file, there was a section that looks like the following:
public function filterByKeywords($keywords) { $expressions = array( $this->query->expr()->like('psi.cName', ':keywords'), $this->query->expr()->like('psi.cDescription', ':keywords'), $this->query->expr()->like('psi.content', ':keywords') );
So if I understand this properly, I need to create an application/src/Page directory and create the PageList.php file there. And then in the section I posted above, I need to add the line you indicated. That way, I'm not overwriting core files, but I'm still adding the functionality in the right location.
Is that close to right? And this would allow my users to do a search on, for example, "883" and it would return the "[site]/index.php?cID=883" page as a result?
Exactly right, make sure to update the namespace to Application at the top too.
Hello again, hutman.
Unfortunately, I'm not having any success with this solution.
I created the application/src/Page directory, copied the PageList.php file there, and then updated the filterByKeywords function as follows:
Then, I updated the namespace at the top of the file to:
I tested the search function and it failed to locate a page based on cID.
I thought perhaps I had misread your comment, so I changed the namespace to "Application;" but that failed to work, as well.
I changed it to "Application\Src\Page;" too, but no luck.
Am I missing something or doing something wrong?
Unfortunately, I'm not having any success with this solution.
I created the application/src/Page directory, copied the PageList.php file there, and then updated the filterByKeywords function as follows:
public function filterByKeywords($keywords) { $expressions = array( $this->query->expr()->like('psi.cName', ':keywords'), $this->query->expr()->like('psi.cDescription', ':keywords'), $this->query->expr()->like('psi.content', ':keywords'), $this->query->expr()->like('psi.cID', ':keywords') );
Then, I updated the namespace at the top of the file to:
namespace Application\Core\Page;
I tested the search function and it failed to locate a page based on cID.
I thought perhaps I had misread your comment, so I changed the namespace to "Application;" but that failed to work, as well.
I changed it to "Application\Src\Page;" too, but no luck.
Am I missing something or doing something wrong?
Okay, so to experiment a bit, I went into my dev environment and updated the core PageList.php file at /concrete/src/Page with the suggested change. This fix didn't work to allow searching on the cID, either.
I guess there may be something more to this than just the one line.
I guess there may be something more to this than just the one line.
I appologize, I am just getting started with 5.7 and I didn't realize that this was stated about overrides "Many files can be overridden in concrete5 simply by providing a file at a specific path. Pretty much the only exclusion to what can be overridden by path is the contents of concrete/src/."
So I guess you have to make that change in the concrete folder. After you make the change make sure to clear your cache. If you have the cache turned on this change might not be recognized.
So I guess you have to make that change in the concrete folder. After you make the change make sure to clear your cache. If you have the cache turned on this change might not be recognized.
@campbell
If you can't override the PageList class, you can try overriding the Search block controller to use a class that extends PageList.
- create a file called CidSearch.php
application\src\CidSearch.php
- add the following code to extend the PageList class and override the filterByKeywords() method
- override the the Search block controller
copy controller.php:
concrete\blocks\search\controller.php
paste controller.php:
application\blocks\search\controller.php
- in the copied controller.php change the namespace
from:
namespace Concrete\Block\Search;
to:
namespace Application\Block\Search;
- change the PageList class import
from:
use Concrete\Core\Page\PageList;
to:
use Application\Src\CidSearch as PageList;
I tried this and it appears to work correctly. Don't test this on a production install, please.
If you can't override the PageList class, you can try overriding the Search block controller to use a class that extends PageList.
- create a file called CidSearch.php
application\src\CidSearch.php
- add the following code to extend the PageList class and override the filterByKeywords() method
<?php namespace Application\Src; use Concrete\Core\Page\PageList; class CidSearch extends PageList { public function filterByKeywords($keywords) { $expressions = array( $this->query->expr()->like('psi.cName', ':keywords'), $this->query->expr()->like('psi.cDescription', ':keywords'), $this->query->expr()->like('psi.content', ':keywords'), $this->query->expr()->like('psi.cID', ':keywords') ); $keys = \CollectionAttributeKey::getSearchableIndexedList(); foreach ($keys as $ak) {
Viewing 15 lines of 23 lines. View entire code block.
- override the the Search block controller
copy controller.php:
concrete\blocks\search\controller.php
paste controller.php:
application\blocks\search\controller.php
- in the copied controller.php change the namespace
from:
namespace Concrete\Block\Search;
to:
namespace Application\Block\Search;
- change the PageList class import
from:
use Concrete\Core\Page\PageList;
to:
use Application\Src\CidSearch as PageList;
I tried this and it appears to work correctly. Don't test this on a production install, please.
I could be wrong, but wouldn't adding "Procedure 456" to the meta description and/or keywords make these instantly searchable?
It would, but I was hoping to find a solution that would not require that manual step each time. My plan has been to incorporate something like that if an automated solution was unavailable.
Into the expressions array.