How would you do semantic search with CMSMS?

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
asdf
Forum Members
Forum Members
Posts: 39
Joined: Thu Jul 08, 2010 1:11 pm

How would you do semantic search with CMSMS?

Post by asdf »

I have set of pages, one section of the site, that I need to search in semantic way. Let's say it's sort of person index / list of biographies. There's need to find people who speak German, but it's not a good idea to simply search for string German as it would find the one where text says "her grandparents are German". Also it should be possible to search by profession, e.g. police, but not find him who got in trouble with the police in college. As said, it's one section of the side, side-wide search is out of question. I hope you got the picture.

The pages exist except for the metadata that would be used for searching so creating a real database is not the quickest way to go. At first I considered tags, but at least Simple Tagging module is too limited, it's not possible to classify tags. I think extra page attributes could work, but they're only three and we need 4-5 classes, so it wouldn't be a perfect solution.

Maybe some sort of product catalogue could be used? There's at least Products and Cataloger modules but I'm not sure can they be used with existing pages. I'm also pretty sure someone has already solved similar problem :)
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1967
Joined: Mon Jan 29, 2007 4:47 pm

Re: How would you do semantic search with CMSMS?

Post by Jo Morg »

Not sure if it fits your needs but I'm doing something similar, and using CompanyDirectory... still testing but, so far, with good results.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
User avatar
myshko
Forum Members
Forum Members
Posts: 102
Joined: Wed Feb 07, 2007 2:36 pm

Re: How would you do semantic search with CMSMS?

Post by myshko »

Hi asdf,

Not sure if this helps, but if you are considering using the extra attributes, you could perhaps use the {content} tag in your page template, make it one line and apply a smarty parameter to it?

For example:

{content block="search_tag" label="Search Tag" oneline="true" assign=searchtag}

Then you could set a value, callable with $searchtag

There's full help info in 'Extensions > Tags > Content'

Regards,

Mikey
asdf
Forum Members
Forum Members
Posts: 39
Joined: Thu Jul 08, 2010 1:11 pm

Re: How would you do semantic search with CMSMS?

Post by asdf »

Thanks for suggestions, I'll have a look at both.

In fact I tried content blocks already but was not able to restrict standard search module to look in those only. But maybe there's a way I'll figure out now that I can get back to this question.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: How would you do semantic search with CMSMS?

Post by psy »

This seems to work if I understand the question correctly, ie you want to display only the results of a search based on a word/phrase contained in a user-defined content block.

Firstly, create a MenuManager template called 'getalias'. It doesn't need to contain anything, we only want the node list. Just to have something in the content area, you can leave {if $count > 0}{/if}.

Next, modify the Search result template as follows:

Code: Select all

{cms_module module=MenuManager template=getalias}
<h3>{$searchresultsfor} "{$phrase}"</h3>
{if $itemcount > 0}
<ul>
    {foreach from=$results item=entry}
	    {foreach from=$nodelist item=node}
		    {if $entry->url eq  $node->url}
			    {capture assign=blockcontent}{$cgsimple->get_page_content($node->alias,'name_of_your_content_block')}{/capture}
				    {if $blockcontent|strpos:$phrase !== false}
				    <li>
				        {$entry->title} - <a href="{$entry->url}">{$entry->urltxt}</a>
				        ({$entry->weight}%)
				    </li>
				{/if}
		    {/if}
	    {/foreach}
    {/foreach}
</ul>
<p>
    {$timetaken}: {$timetook}
</p>
{else}
<p>
    <strong>{$noresultsfound}</strong>
</p>
{/if}
How it works:

1. We retrieve the nodelist which contains the page alias and also conveniently, the page URL.
2. We iterate through the search results and compare the search entry URL with the nodelist URL
3. When a match is found, we retrieve the particular content block using CGSimpleSmarty with the corresponding $node->alias
4. Next, we search the content block for the search phrase {$phrase}
5. If a match is found, it outputs the result or else moves onto the next search result.

Please Note: CGSimpleSmarty must be installed.

hth
psy
applejack
Power Poster
Power Poster
Posts: 1014
Joined: Fri Mar 30, 2007 2:28 am
Location: London

Re: How would you do semantic search with CMSMS?

Post by applejack »

Very useful psy just used on a multilingual site in order to restrict the search to specific language. Just a couple of things you may wish to use stripos instead as strpos is case sensitive and also add a counter inside the {if $blockcontent|strpos:$phrase !== false} statement in order to use if no results found.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: How would you do semantic search with CMSMS?

Post by psy »

Thanks Applejack :)

One further refinement to speed things up, change:

Code: Select all

{capture assign=blockcontent}{$cgsimple->get_page_content($node->alias,'name_of_your_content_block')}{/capture}
to

Code: Select all

{$cgsimple->get_page_content($node->alias,'name_of_your_content_block','blockcontent')}
psy
applejack
Power Poster
Power Poster
Posts: 1014
Joined: Fri Mar 30, 2007 2:28 am
Location: London

Re: How would you do semantic search with CMSMS?

Post by applejack »

I would leave as is using capture as more flexible in case you want to include other content blocks such as title ala {$cgsimple->get_page_title($node->alias)} etc etc
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: How would you do semantic search with CMSMS?

Post by psy »

Good point.

The suggestion was based on Calguy's comment on http://forum.cmsmadesimple.org/viewtopi ... re#p293838 ie don't use {capture} unless necessary as it's slow.
applejack
Power Poster
Power Poster
Posts: 1014
Joined: Fri Mar 30, 2007 2:28 am
Location: London

Re: How would you do semantic search with CMSMS?

Post by applejack »

You could perhaps use |cat but...
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: How would you do semantic search with CMSMS?

Post by psy »

Yep, whatever works. ;)

Another thing you may want to change is the MenuManager call to

Code: Select all

{cms_module module=MenuManager template=getalias show_all="0"}
in case the search result page is set to not show in the menu. This will include it in the $nodelist.
applejack
Power Poster
Power Poster
Posts: 1014
Joined: Fri Mar 30, 2007 2:28 am
Location: London

Re: How would you do semantic search with CMSMS?

Post by applejack »

I have the search results page set as not show in menu and your code works fine.

Also you can just use {menu template='getalias'}
Last edited by applejack on Sun Mar 10, 2013 2:34 am, edited 2 times in total.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: How would you do semantic search with CMSMS?

Post by psy »

I was a bit ambiguous, not the Search module results page, BUT the $nodelist containing the pages from the MenuManager call, ie you want to ensure that ALL active pages are included in $nodelist, not just those marked as "Show in Menu".

Again, yep, you can use the shorthand version of the MenuManager tag. Force of habit over many years to write module tags the full way in other module templates.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: How would you do semantic search with CMSMS?

Post by psy »

Oh and of course, you'll then have to filter out the Search results page URL otherwise you may end up in an endless loop. :)
applejack
Power Poster
Power Poster
Posts: 1014
Joined: Fri Mar 30, 2007 2:28 am
Location: London

Re: How would you do semantic search with CMSMS?

Post by applejack »

For anyone else this may be useful UDT for getting the page alias in other instances

http://forum.cmsmadesimple.org/viewtopi ... as#p267095
Post Reply

Return to “The Lounge”