<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Loftux AB &#187; search</title>
	<atom:link href="http://loftux.com/tag/search/feed/" rel="self" type="application/rss+xml" />
	<link>http://loftux.com</link>
	<description>Dokumenthantering och informationshantering med öppen källkod</description>
	<lastBuildDate>Fri, 04 May 2012 11:11:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Advanced search in Alfresco Share</title>
		<link>http://loftux.com/2010/02/25/advanced-search-in-alfresco-share/</link>
		<comments>http://loftux.com/2010/02/25/advanced-search-in-alfresco-share/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 14:20:23 +0000</pubDate>
		<dc:creator>Peter Löfgren</dc:creator>
				<category><![CDATA[Uncategorized @en]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[share]]></category>

		<guid isPermaLink="false">http://loftux.se/?p=275</guid>
		<description><![CDATA[<p>The current version of Alfesco Share lacks an advanced search for your custom metadata. It is not Alfresco and Lucene that doesn&#8217;t have this capability, what is missing is an implementation of advanced search. According to Alfresco <a href="http://wiki.alfresco.com/wiki/Roadmap">roadmap</a> we will have to wait until end of 2010 before we get this as a standard [...]]]></description>
			<content:encoded><![CDATA[<p>The current version of Alfesco Share lacks an advanced search for your custom metadata. It is not Alfresco and Lucene that doesn&#8217;t have this capability, what is missing is an implementation of advanced search. According to Alfresco <a href="http://wiki.alfresco.com/wiki/Roadmap">roadmap</a> we will have to wait until end of 2010 before we get this as a standard functionality, meantime we will have to solve this ourself, and this is an example of how.<br />
<span id="more-275"></span><br />
To create the actual search form is the easy part, harder is to create the hit list. So we start by finding out if there is a list we can reuse already available in Alfresco, for example the one in Document Library. I prefer that list to the one provided by quick search, as we can get directly to the menu options and start working with the document. </p>
<p>To the left in the Document Library page there are some Quick searches like &#8220;I&#8217;m Editing&#8221;. This implies that we should have a way of adding our own. And you can, Sebastian Wenzky has written a good <a href="http://portal.krypthonas.de/2009/08/04/alfresco-32-share-pimp-the-document-library-for-custom-document-types/">howto</a>. The key is the file filter.lib.js available in<br />
tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary.<br />
Looking at that you can see that you actually can call the Document Library page with parameters, for example<br />
<a href="http://localhost:8080/share/page/site/alfresco/documentlibrary?filter=editingMe">http://localhost:8080/share/page/site/alfresco/documentlibrary?filter=editingMe</a> and end up directly on the built in searches.</p>
<p>So we now have to create our own filter for the switch statement in filter.lib.js so that we get an url like documentlibrary?filter=customQuery. But we also need a way to pass our search data, and luckily there is a parameter already defined that can be used for that purpose, filterData, that is passed all the way by share to filter.lib.js. Our search url will the be /documentlibrary?filter=customQuery&#038;filterData=/your search parameters/.</p>
<p>Her is some sample code to be added in filter.lib.js, part of it is reused from what is in filter.lib.js. You will have to adapt the code to fit you needs and custom metadata.</p>
<pre class="brush: jscript; collapse: true; light: false; title: ; toolbar: true; notranslate">
         case &quot;customQuery&quot;:
             filterQuery = &quot;+PATH:\&quot;&quot; + parsedArgs.rootNode.qnamePath + &quot;//*\&quot;&quot;;
             if(args.filterData.length&gt;0)
             {
            	 var strData=decodeURI(args.filterData);
            	 logger.log(strData);
            	 var queryArray=strData.split(&quot;|&quot;);
            	 for(var i=0;i&lt;queryArray.length;i++)
            	 {
            		var strQuery=queryArray[i];
            		var strQueryArray=strQuery.split(&quot;_&quot;);
            		logger.log(strQueryArray[0]);
            		logger.log(strQueryArray[1]);
            		switch (strQueryArray[0])
            		{
            		case &quot;ftx&quot;:
             			var ftterm=strQueryArray[1];
            			var ftquery=&quot; +(&quot;;

            		      var ftterms = ftterm.split(/\s/), i, j, t;

            		      for (i = 0, j = ftterms.length; i &lt; j; i++)
            		      {
            		         t = ftterms[i];
            		         // remove quotes - TODO: add support for quoted terms later
            		         t = t.replace(/\&quot;/g, &quot;&quot;);
            		         if (t.length !== 0)
            		         {
            		            switch (t.toLowerCase())
            		            {
            		               case &quot;and&quot;:
            		                  if (i &lt; j - 1 &amp;&amp; ftterms[i + 1].length !== 0)
            		                  {
            		                     ftquery += &quot;AND &quot;;
            		                  }
            		                  break;

            		               case &quot;or&quot;:
            		                  break;

            		               case &quot;not&quot;:
            		                  if (i &lt; j - 1 &amp;&amp; ftterms[i + 1].length !== 0)
            		                  {
            		                     ftquery += &quot;NOT &quot;;
            		                  }
            		                  break;

            		               default:
            		                  ftquery += &quot;TEXT:\&quot;&quot; + t + &quot;\&quot;&quot; + &quot; &quot;;
            		               		break;

            		            }
            		         }
            		      }
            		      filterQuery += ftquery+&quot;) &quot;;

            			break;
            		case &quot;docid&quot;:
            			filterQuery += &quot; +@sys\\:node-dbid:&quot;+strQueryArray[1];
            			break;
            		case &quot;contractid&quot;:
            			filterQuery += &quot; +@ltx\\:contractid:&quot;+strQueryArray[1];
            			break;
            		case &quot;doctype&quot;:
            			filterQuery += &quot; +TYPE:\&quot;{http://www.loftux.se/model}&quot;+strQueryArray[1]+&quot;\&quot;&quot;;
            			break;
            		case &quot;file&quot;:
            			//we need to search both with and without wildcards. Sometime there is a hit
            			//sometime not if we dont depending on search term. Makes results more predictable
            			filterQuery += &quot; +(@cm\\:name:&quot;+strQueryArray[1] + &quot; OR @cm\\:name:*&quot;+strQueryArray[1]+&quot;*)&quot; ;
            			break;
                    case &quot;tag&quot;:
                    	filterQuery += &quot; +PATH:\&quot;/cm:taggable/cm:&quot; + search.ISO9075Encode(strQueryArray[1].toLowerCase()) + &quot;/member\&quot;&quot;;
                        break;
                    case &quot;sort&quot;:

                    	if(strQueryArray[1]==&quot;editdesc&quot;)
                    	{
                    		filterParams.sort = [
                    		{
                    		column: &quot;@{http://www.alfresco.org/model/content/1.0}modified&quot;,
                    		ascending: false
                    		}];
                    	}
                    	if(strQueryArray[1]==&quot;editasc&quot;)
                    	{
                    		filterParams.sort = [
                    		{
                    		column: &quot;@{http://www.alfresco.org/model/content/1.0}modified&quot;,
                    		ascending: true
                    		}];
                    	}

                    	break;
            		}
            	 }

             }
             filterParams.query = filterQuery + filterQueryDefaults;
             filterParams.query += &quot; &quot; + (Filters.TYPE_MAP[&quot;documents&quot;]);
</pre>
<p>We now can call the Document Library page with (example)<br />
/documentlibrary?filter=customQuery&#038;filterData=ftx_test|doctype_contract|sort_editdesc.<br />
This is as you can tell not a generic solution, each parameter is built up from a field in your search form. The search above would do a fulltext search on &#8220;test&#8221; and a document of custom type contract, sorted descending on last edit date.</p>
<p>To display correctly in Share Document Library, we also have to add our customQuery to Share. Find the file<br />
site-webscripts/org/alfresco/components/documentlibrary/filter.get.config.xml and add a new filter filter.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;filters&gt;
   &lt;filter id=&quot;all&quot; label=&quot;link.all&quot; /&gt;
   &lt;filter id=&quot;editingMe&quot; label=&quot;link.editingMe&quot; /&gt;
   &lt;filter id=&quot;editingOthers&quot; label=&quot;link.editingOthers&quot; /&gt;
   &lt;filter id=&quot;recentlyModified&quot; label=&quot;link.recentlyModified&quot; /&gt;
   &lt;filter id=&quot;recentlyAdded&quot; label=&quot;link.recentlyAdded&quot; /&gt;
   &lt;filter id=&quot;favouriteDocuments&quot; label=&quot;link.favouriteDocuments&quot; /&gt;
   &lt;filter id=&quot;customQuery&quot; label=&quot;link.customQuery&quot; /&gt;
&lt;/filters&gt;
</pre>
<p>Our filter is to be called by a special search page, so we don&#8217;t want i clickable link to apper. We can do this simply by making the label above blank in the file filter.get.properties (found in the same folder as above)<br />
link.customQuery=<br />
Also in the file toolbar.get.properties we have to add some labels for the result list to appera nicely.<br />
description.customQuery=Custom Search<br />
description.customQuery.more=<br />
If you have added more lanugages to share, add the same lines for corresponding properties files.</p>
<p>Now you just have to create you search form. you can do that by adding a custom <a href="http://www.google.se/search?q=alfresco+creating+a+custom+dashlet">Dashlet</a>, or with <a href="http://wiki.alfresco.com/wiki/Share_Custom_Pages">a custom Share page</a>. I will not describe this in this post, I may make a follow up post for that.</p>
<p>Note that Alfresco is also adding similar functionality to Share for version 3.3. It will be for the Share quick search box, where you can add parameters to search specific metadata by writing for example description:important and get an url like /share/page/search?t=description:important. But to my understanding this will only be by using the quick search box, and therefor more for advanced users. But this is certainly an option to wait for this functionality, and instead create you custom search page to call this url.</p>
]]></content:encoded>
			<wfw:commentRss>http://loftux.com/2010/02/25/advanced-search-in-alfresco-share/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

