Monday, April 12, 2010

Alfresco Search Customization

As per Alfresco documentation default search uses a Boolean "Implied AND" as like Google, Yahoo or any major search engine works. But the behavior of alfresco is seems to be using Boolean “Implied OR”.
But Customization of such kind of search is made easy by Alfresco when it comes to customize Alfresco Web Client.
Let’s go by example.
We have few resume stored as word document in our repository if we do search on Alfresco repository using keywords (java alfresco) it gives all the documents which has meta data(or Full text search) either as Java or as alfresco. But we are intended to search all those documents which have Java and alfresco both skill sets. It is the situation where alfresco default search is based on “Implied OR”.
We can configure this on Alfresco web-client customization if we are using SearchContext . We need to add the configuration in web-client-config-custom.xml as below

<alfresco-config>
   <config>
      <client>
        <!-- set this value to true to enable AND text terms for simple/advanced search by default -->
        <search-and-terms>true</search-and-terms>
      </client>
   </config>
</alfresco-config>

If you are using Search Service (Search using API) then you can set SearchParameter default operator as “implied AND” as below

SearchParameters sp = new SearchParameters();
sp.addStore(Repository.getStoreRef());
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery(query);
sp.setDefaultOperator(SearchParameters.AND);
ResultSet nodeRefs = searchService.query(sp);

With this kind of customization we are sure that we can use exact search as like Google in our Alfresco repository.

Monday, March 29, 2010

Custom Content Transformer

Alfresco has content transformer for most of mime type we are using day to day. But We wanted to have Custom Content Transformer,to show preview of .xfdl file.

.xfdl is extension for electronic form provided by Lotus Forms. This blog is more of creating a Custom Content Transformer for xfdl mime type.

1.How to register new Content Type i.e. “.xfdl”
Create new file “mimetype-custom-extensions.xml” at level “alfresco/mimetype” parallel level to “alfresco/extension” it should not go under “alfresco/extension” e.g. say mimetype-custom-extensions.xml
In this file we configure alfresco-config for area mimetype-map. Define correct mimetype for your extension here.


2.How to register new Custom Content Transformer
Create new file custom-services-context.xml under “alfresco/extension” folder e.g. custom-services-context.xml

In this file we need to define bean for "mimetypeConfigService" and new bean "transformer.xfdlToText" for Transformer "XFDLContentTransformer".


3. Create Custom Content Transformer “XFDLContentTransformer.java”
This is class where Transformation will take place for you extension mimetype. This class will extends the functionality from "AbstractContentTransformer" . This class uses a "transformText" method to transform it. You have different for you different extension and mimetype.


You can download the code from here ...
http://docs.google.com/leaf?id=0B2GTDzbcX3UsYjliNTAxMjYtNTkwMi00YmI4LTkyODgtZTA3OGQwNjQyN2Qw&hl=en

Wednesday, January 27, 2010

Alfresco FirstFoundationClient (How to setup and Run)

With this blog you will be able to setup and Run FirstFoundationClient sample of Alfresco.

1. Import FirstFoundationClient Project in eclipse (Assuming you are using eclipse).
2. Specify repository properties with “source/alfresco/extension/custom-repository.properties”.


#
# Sample custom content and index data location
#

dir.root=D:/javatools/alfrescorepo/alf_data
dir.indexes=D:/javatools/alfrescorepo/alf_data/lucene-indexes

#
# Sample database connection properties
#
db.name=alfrescorepodb
db.username=workalfresco
db.password=workalfresco
db.driver=org.postgresql.Driver
db.url=jdbc:postgresql://localhost:5432/alfrescorepodb


3. Create New file “custom-hibernate-dialect.properties” under “source/alfresco/extension”.
#
# Sample Hibernate configuration for changing Database dialect
# For a full list: http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#configuration-optional-dialects
#


#
# PostgreSQL dialect
#
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.query.substitutions=true TRUE, false FALSE


4. Create new bean definition “hibernateConfigProperties” in “source/alfresco/extension/custom-repository-context.xml”.

<bean id="hibernateConfigProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:alfresco/domain/hibernate-cfg.properties</value>

<!-- Override hibernate dialect -->
<value>classpath:alfresco/extension/custom-hibernate-dialect.properties</value>
</list>
</property>
</bean>


5. Run FirstFoundationClient.java with main method.

Note:
1. If you are using PostgreSQL or any other database please provide driver classpath or add additional jar to your project.
2. If your alfresco tomcat server is already Running Please try to change avm.jmxrmi.port from 50500 to 50502 and avm.remote.port from 1313 to 1315 in “/source/alfresco/extension/custom-alfresco-shared.properties”.