Page 1 of 1

How would you do semantic search with CMSMS?

Posted: Tue Apr 10, 2012 3:10 pm
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 :)

Re: How would you do semantic search with CMSMS?

Posted: Tue Apr 10, 2012 3:37 pm
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.

Re: How would you do semantic search with CMSMS?

Posted: Wed Apr 11, 2012 2:31 am
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

Re: How would you do semantic search with CMSMS?

Posted: Mon Apr 16, 2012 3:16 pm
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.

Re: How would you do semantic search with CMSMS?

Posted: Fri Jul 13, 2012 7:06 am
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

Re: How would you do semantic search with CMSMS?

Posted: Sat Mar 09, 2013 3:36 pm
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.

Re: How would you do semantic search with CMSMS?

Posted: Sat Mar 09, 2013 11:46 pm
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

Re: How would you do semantic search with CMSMS?

Posted: Sun Mar 10, 2013 12:07 am
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

Re: How would you do semantic search with CMSMS?

Posted: Sun Mar 10, 2013 12:21 am
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.

Re: How would you do semantic search with CMSMS?

Posted: Sun Mar 10, 2013 1:14 am
by applejack
You could perhaps use |cat but...

Re: How would you do semantic search with CMSMS?

Posted: Sun Mar 10, 2013 2:08 am
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.

Re: How would you do semantic search with CMSMS?

Posted: Sun Mar 10, 2013 2:21 am
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'}

Re: How would you do semantic search with CMSMS?

Posted: Sun Mar 10, 2013 2:29 am
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.

Re: How would you do semantic search with CMSMS?

Posted: Sun Mar 10, 2013 2:37 am
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. :)

Re: How would you do semantic search with CMSMS?

Posted: Sun Mar 10, 2013 2:38 am
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