solved Make Custom Module Pages Searchable

PatriaCo
PatriaCo
@the-patria-company
6 years ago
349 posts
When referencing the last entry in this forum post:

https://www.jamroom.net/the-jamroom-network/forum/my_posts/59966/custom-module-pages-in-sitemap

What is the best method I should use to make these pages searchable by jrSearch?


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3

updated by @the-patria-company: 04/20/19 01:26:50PM
michael
@michael
6 years ago
7,692 posts
Jamroom jrSearch doesn't spider content, it searches the database, so if you're writing text into those .tpl files jrSearch isn't going to find it.

If they have corresponding datastores that point to the pages, then that would be a different story.
PatriaCo
PatriaCo
@the-patria-company
6 years ago
349 posts
Is there a way to add the pages, like a directory, into the datastore for the module?


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3
PatriaCo
PatriaCo
@the-patria-company
6 years ago
349 posts
OK, so I have my schema set up and I simply want to add a directory of pages to the datastore. I also want the integrity check to check the directory so that if any changes are made to the module's index.php (such as adding cities) that the datastore will not contain duplicates.

My module's index.php (with the proposed save to datastore function)
function view_myCustomModule_default($_post, $_user, $_conf)
{ switch ($_post['option']) { case'my-custom-module-page-houston': case'my-custom-module-page-chicago': case'my-custom-module-page-new-york': return jrCore_parse_template('my-custom-module-page.tpl', $_rep, 'myCustomModule'); break; } } //------------------------------ // create pages directory in datastore //------------------------------ function view_myCustomModule_create_dir($_post, $_user, $_conf)
{ $_sv = array( 'page' => "{$_conf['jrCore_base_url']}/{$url}/my-custom-module-page-houston", ); $_sv = array( 'page' => "{$_conf['jrCore_base_url']}/{$url}/my-custom-module-page-chicago", ); $_sv = array( 'page' => "{$_conf['jrCore_base_url']}/{$url}/my-custom-module-page-new-york", ); }

Am I going in the right direction? I don't need to "view" the function, but I am not sure of the right syntax to use here. Thanks for the help. :)


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3

updated by @the-patria-company: 12/11/18 08:43:06AM
michael
@michael
6 years ago
7,692 posts
when you have a datastore it will have a prefix. like audio is 'audio_' and blog is 'blog_'. You can then add these to the search modules extra search fields. so 'audio_lyrics' 'blog_text' and the saved info will be searchable.
PatriaCo
PatriaCo
@the-patria-company
6 years ago
349 posts
Thanks @michael


So I see three possibilities, but I am not sure of the best way.

#1. I could make an admin only page view with a form (that allows multiple data entries at once).
or
#2. I could hard code the data to enter from the module's index.php, but that could lead to an unnecessarily large file.
or
#3. I could have the module search the sitemap and create the datastore entries. (not sure if this is possible)

Which of these options is the best to pursue?


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3
michael
@michael
6 years ago
7,692 posts
if it was me wanting this, I would put the data you wanted made searchable into the database.

'yourmodule_pagetext'

Then in the pages .tpl file I would retrieve it and output it to the page:
{$yourmodule_pagetext}

Just like the jrPage module does now.
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
Yes, @michael I completely agree. I am just unsure of the best way to enter the over 5000 entries. If I could "harvest" the page urls from the sitemap and add them to the datastore using a simple search query that would be great.

Another thought I had was connected to the fact that I am already adding the pages to the site map via a function in my module.

Is there a similar statement that I can code to add these same urls directly into the datastore?

Can I add something like this to my module's include.php?

function myCustomModule_addURLToDataStore_save($_post,  &$_user,  &$_conf)
{ $url = jrCore_get_module_url('myCustomModule'); $_data[] = "{$_conf['jrCore_base_url']}/{$url}/birmingham-alabama-electricians"; $_data[] = "{$_conf['jrCore_base_url']}/{$url}/montgomery-alabama-electricians"; $_data[] = "{$_conf['jrCore_base_url']}/{$url}/huntsville-alabama-electricians"; $_data = jrCore_form_get_save_data('myCustomModule', 'create', $_post); }

I can see from other modules that a view function is used in the index.php file of the module, as the data is being saved from a form, but I do not need a form as I would like to hard code the URLs that I want to be added to the datastore. Similar to the way that I added the list of URLs to the Sitemap. I know that my code is not correct, but I hope that I am getting close. I would also like to make sure that this way of adding data into the datastore does not produce duplicates.

Any assistance would be greatly appreciated. THANKS!!


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3
michael
@michael
5 years ago
7,692 posts
adding the URL's to the datastore doesn't feel right to me. The datastore stores data and the search function searches the data. so if you want the page to be found by the search function you need to add the data that is searched to the datastore.

however the data got to the pages, its probably stored somewhere, so cant you take that and put it into the datastore?
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
I am probably not understanding something, sorry. I have two goals.

#1. I want the pages from my module to be available in the jrSearch Results

#2. I want to access each page title and url using {jrCore_list

There are only two places where I can find the data containing my list of pages, (1) hard-coded into my module's include.php function and (2) in the Sitemap xml file. I was hoping I could tap into a sitemap datastore, but that was a no-go.

Is it even necessary to get this data into my module's datastore, or is it already available somewhere else, via the sitemap module?


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3
brian
@brian
5 years ago
10,136 posts
To make your module work with search you just need to register for it in your module's init function:

jrCore_register_module_feature('jrSearch', 'search_fields', 'myCustomModule', 'key_one,key_two', 'Item Title');

Where:

key_one and key_two are the datastore key fields you want to search (you can have from 1 to N fields - as many as you want) and "Item Title" is the title that they will show up under when a result is displayed.

For jrCore_list you don't have to do anything at all - it is automatic once you use a datastore in your module.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
PERFECT!

So this goes back to my earlier question of the best way to populate the datastore. Is there a way to bulk import or hardcode or take the data that I want to add from the sitemap module? Adding them one at a time via a form would take a very long time.


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3
brian
@brian
5 years ago
10,136 posts
PatriaCo:
PERFECT!

So this goes back to my earlier question of the best way to populate the datastore. Is there a way to bulk import or hardcode or take the data that I want to add from the sitemap module? Adding them one at a time via a form would take a very long time.

There's no built in way to do that - you'd have to create code that would parse out your sitemap and insert them into the DS.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
OK, I am going to give this a try :) I hope I am close. Areas, where my php is very weak, are notated in dbl ?? Thanks again for helping me through my learning curve.

function myCustomModule_createPageDirectoryInDatastore($_data, $_user, $_conf, $_args, $event)
{ $curl = curl_init(); //Determine the number of Sitemaps to Parse from ($jamroom_url)/sitemap.xml $smurl = "{$_conf['jrCore_base_url']}/sitemap.xml"; curl_setopt($curl, CURLOPT_URL, $smurl); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $smresult = curl_exec($curl); $sitemaps = array(); preg_match_all('!<loc>{$_conf['jrCore_base_url']}\/sitemap\/sitemap(.*?).xml<\/loc>!',$smresult,$match); $sitemaps['map'] = $match[1]; $smcount = count($sitemaps); //Begin parsing sitemaps and finding url matches for the module that we are searching for $murl = jrCore_get_module_url('myCustomModule'); //Open each sitemap xml page and begin parsing for (// ?? repeat $smcount ??) $url = "{$_conf['jrCore_base_url']}/sitemap[//?? $sitemaps array numerical entry for 'map' ??].xml"; curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($curl); $pages = array(); //This should capture our page data to add to the array preg_match_all('!<loc>{$_conf['jrCore_base_url']}\/{$murl}\/(.*?)<\/loc>!',$result,$match); $pages['name'] = $match[1]; //Check Datastore for duplicates and remove from array ?? ?? //Enter new $pages array results into the module's datastore ?? ?? }

Lastly, I would like to create a button that initiates the function in the "Tools" tab (which was automatically created with the module's datastore). Could I also get some help with that, please?


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3

updated by @the-patria-company: 01/14/19 04:14:45PM
brian
@brian
5 years ago
10,136 posts
I'm struggling to figure out what you are trying to do here. It sounds like you are trying to take the URLs in your sitemap.xml file and put them into a DS so they will show up in search? Is that correct? If so, you do not need to do any of this. The sitemap.xml file is generated off of the existing DS's in your Jamroom, so the data you are trying to ADD to search is already available in search.

So you have a profile URL like this:

huntsville-alabama-electricians

That's already going to be found in your jrProfile DS. There's no sense creating ANOTHER module to insert items into a DS, which in turn provides a search key for an already existing search. Does that make sense?


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
It does make sense; except, the pages I am searching for are not profiles. The pages that I need to add to the module's datastore were pseudo-created via the module's include.php by adding them to the sitemap via the hardcoded function that you helped me with:

https://www.jamroom.net/the-jamroom-network/forum/my_posts/59966/custom-module-pages-in-sitemap


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3

updated by @the-patria-company: 01/14/19 03:57:16PM
brian
@brian
5 years ago
10,136 posts
OK instead of going this route then, you need to just UPDATE your existing module that is writing the pages to the sitemap and in the same process add them to the datastore. You already have the URLs right there - there is no need to go out and re-read them back from the sitemap.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
Great! That will be much easier. Earlier in this thread I attempted to write such a code, but I know I am off by a bit.

PatriaCo:
OK, so I have my schema set up and I simply want to add a directory of pages to the datastore. I also want the integrity check to check the directory so that if any changes are made to the module's index.php (such as adding cities) that the datastore will not contain duplicates.

My module's index.php (with the proposed save to datastore function)
function view_myCustomModule_default($_post, $_user, $_conf)
{ switch ($_post['option']) { case'my-custom-module-page-houston': case'my-custom-module-page-chicago': case'my-custom-module-page-new-york': return jrCore_parse_template('my-custom-module-page.tpl', $_rep, 'myCustomModule'); break; } } //------------------------------ // create pages directory in datastore //------------------------------ function view_myCustomModule_create_dir($_post, $_user, $_conf)
{ $_sv = array( 'page' => "{$_conf['jrCore_base_url']}/{$url}/my-custom-module-page-houston", ); $_sv = array( 'page' => "{$_conf['jrCore_base_url']}/{$url}/my-custom-module-page-chicago", ); $_sv = array( 'page' => "{$_conf['jrCore_base_url']}/{$url}/my-custom-module-page-new-york", ); }

Am I going in the right direction? I don't need to "view" the function, but I am not sure of the right syntax to use here. Thanks for the help. :)



--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3

updated by @the-patria-company: 01/16/19 01:44:28PM
brian
@brian
5 years ago
10,136 posts
There's a number of issues here in this code - I get the feeling you're not really understanding what you're doing or why you're doing it, and instead are just throwing some code into the module and hoping it works?

Your second view function is useless - remove it. The first one has issues but the basic idea is:

function view_myCustomModule_default($_post, $_user, $_conf)
{ switch ($_post['option']) { case 'my-custom-module-page-houston': case 'my-custom-module-page-chicago': case 'my-custom-module-page-new-york': $_data = jrCore_db_get_item_by_key('myCustomModule', 'mod_page', $_post['option']); if (!$_data || !is_array($_data)) { $_data = array('mod_page' => $_post['option']); jrCore_db_create_item('myCustomModule', $_data); } return jrCore_parse_template('my-custom-module-page.tpl', $_data, 'myCustomModule'); break; } }

What I added is:

- try to get the EXISTING page entry into $_data using jrCore_db_get_item_by_key
- if it does not exist, create it

Note I used "mod_page" here since I have no idea what your DS prefix is, but you will need to change that to be whatever your module prefix is.

This is really as far as we can take coding this for you in the forum - I'd HIGHLY recommend that you spend some time learning PHP development so you know what the code you are putting in the file actually means, etc. You want to be careful and know exactly what (and why) you are doing it, since doing it wrong could mess your site up or expose a security issue.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
PatriaCo
PatriaCo
@the-patria-company
5 years ago
349 posts
Thank you for the help!

I am trying to learn PHP as quickly as possible; however, many times my needs exceed my abilities.

This solution is going to work out very nicely. Thank you again!!


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3

Tags