A robust starter web application to ease Java webapp development.

Home | Tutorials | Demos | Issues

 « Return to Thread: RE: search - integrate compass (lucene) and appfuse

RE: search - integrate compass (lucene) and appfuse

by Matt Stine :: Rate this Message:

Reply to Author | View in Thread

No problem.  Here's the modifications for JSF:

I extracted this from an application that I'm actually building - I
tried to remove all of the stuff specific to us, but something may have
slipped through.  Please give it a try w/ the original tutorial if you
are using JSF.  I'd be glad to help add this to the full tutorial
whenever it goes wiki/article.

First off, dump step 9 from the original tutorial.  We're going to need
JSF equivalents of the Compass-bundled Spring MVC controllers.  Here we
go, with a new step 9.

9. Create two backing beans, one for Index and one for Search.
These are based on the Spring MVC controllers:

/*
 * This code is a derivative of
org.compass.spring.web.mvc.CompassSearchController
 * as dispayed at:
http://svn.opensymphony.com/fisheye/browse/~raw,r=33/compass/trunk/src/m
ain/src/org/compass/spring/web/mvc/CompassIndexController.java
 * and as such requires the addition of this license.
 *
 * Copyright 2004-2006 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package <<YOUR PACKAGE>>.webapp.action;

import org.compass.gps.CompassGps;

/**
 * A JSF backing bean to perform Compass indexing following the same
 * general contract (removing Spring MVC specific code) as
<code>CompassIndexController</code>
 *
 * @author Matt Stine (original author kimchy)
 * @see org.compass.spring.web.mvc.CompassIndexController
 */
public class CompassIndex extends BasePage {

    private CompassGps compassGps;
    private long indexTime;

    public void setCompassGps(CompassGps compassGps) {
        this.compassGps = compassGps;
    }

    public CompassGps getCompassGps() {
        return compassGps;
    }

    public long getIndexTime() {
        return indexTime;
    }

    public void setIndexTime(long indexTime) {
        this.indexTime = indexTime;
    }

    public String doIndex() {
        long time = System.currentTimeMillis();
        getCompassGps().index();
        setIndexTime(System.currentTimeMillis() - time);

        return "indexComplete";
    }
}

/*
 * This code is a derivative of
org.compass.spring.web.mvc.CompassSearchController
 * as dispayed at:
http://svn.opensymphony.com/fisheye/browse/~raw,r=658/compass/trunk/src/
main/src/org/compass/spring/web/mvc/CompassSearchController.java
 * and as such requires the addition of this license.
 *
 * Copyright 2004-2006 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package <<YOUR PACKAGE>>.webapp.action;

import org.compass.core.*;
import org.compass.spring.web.mvc.CompassSearchCommand;
import org.compass.spring.web.mvc.CompassSearchResults;
import org.springframework.util.StringUtils;

/**
 * A JSF backing bean to perform Compass searches following the same
 * general contract (removing most of the Spring MVC specific code) as
<code>CompassSearchController</code>
 *
 * @author Matt Stine (original author kimchy)
 * @see org.compass.spring.web.mvc.CompassSearchController
 */
public class CompassSearch extends BasePage {

    private Compass compass;
    private CompassTemplate compassTemplate;
    private Integer pageSize;
    private CompassSearchResults searchResults;
    private Integer page = new Integer(0);
    private String query;

    public Compass getCompass() {
        return compass;
    }

    public void setCompass(Compass compass) {
        this.compass = compass;
        this.compassTemplate = new CompassTemplate(compass);
    }

    public CompassTemplate getCompassTemplate() {
        return compassTemplate;
    }

    public String getQuery() {
        return query;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public CompassSearchResults getSearchResults() {
        return searchResults;
    }

    public void setSearchResults(CompassSearchResults searchResults) {
        this.searchResults = searchResults;
    }

    public String doSearch() {
        final CompassSearchCommand searchCommand = new
CompassSearchCommand();
        searchCommand.setPage(getPage());
        searchCommand.setQuery(getQuery());
        if (!StringUtils.hasText(searchCommand.getQuery())) {
            return "search";
        }
        searchResults = (CompassSearchResults)
getCompassTemplate().execute(
 
CompassTransaction.TransactionIsolation.READ_ONLY_READ_COMMITTED, new
CompassCallback() {
            public Object doInCompass(CompassSession session) throws
CompassException {
                return performSearch(searchCommand, session);
            }
        });
        return "searchResults";
    }

    protected CompassSearchResults performSearch(CompassSearchCommand
searchCommand, CompassSession session) {
        long time = System.currentTimeMillis();
        CompassQuery query = buildQuery(searchCommand, session);
        CompassHits hits = query.hits();
        CompassDetachedHits detachedHits;
        CompassSearchResults.Page[] pages = null;
        if (pageSize == null) {
            doProcessBeforeDetach(searchCommand, session, hits, -1, -1);
            detachedHits = hits.detach();
        } else {
            int iPageSize = pageSize.intValue();
            int page = 0;
            int hitsLength = hits.getLength();
            if (searchCommand.getPage() != null) {
                page = searchCommand.getPage().intValue();
            }
            int from = page * iPageSize;
            if (from > hits.getLength()) {
                from = hits.getLength() - iPageSize;
                doProcessBeforeDetach(searchCommand, session, hits,
from, hitsLength);
                detachedHits = hits.detach(from, hitsLength);
            } else if ((from + iPageSize) > hitsLength) {
                doProcessBeforeDetach(searchCommand, session, hits,
from, hitsLength);
                detachedHits = hits.detach(from, hitsLength);
            } else {
                doProcessBeforeDetach(searchCommand, session, hits,
from, iPageSize);
                detachedHits = hits.detach(from, iPageSize);
            }
            doProcessAfterDetach(searchCommand, session, detachedHits);
            int numberOfPages = (int) Math.ceil((float) hitsLength /
iPageSize);
            pages = new CompassSearchResults.Page[numberOfPages];
            for (int i = 0; i < pages.length; i++) {
                pages[i] = new CompassSearchResults.Page();
                pages[i].setFrom(i * iPageSize + 1);
                pages[i].setSize(iPageSize);
                pages[i].setTo((i + 1) * iPageSize);
                if (from >= (pages[i].getFrom() - 1) && from <
pages[i].getTo()) {
                    pages[i].setSelected(true);
                } else {
                    pages[i].setSelected(false);
                }
            }
            if (numberOfPages > 0) {
                CompassSearchResults.Page lastPage = pages[numberOfPages
- 1];
                if (lastPage.getTo() > hitsLength) {
                    lastPage.setSize(hitsLength - lastPage.getFrom());
                    lastPage.setTo(hitsLength);
                }
            }
        }
        time = System.currentTimeMillis() - time;
        CompassSearchResults searchResults = new
CompassSearchResults(detachedHits.getHits(), time);
        searchResults.setPages(pages);
        return searchResults;
    }

    /**
     * Acts as an extension point for search controller that wish to
build
     * different CompassQueries. <p/> The default implementation uses
the
     * session to create a query builder and use the queryString option,
i.e.:
     *
<code>session.queryBuilder().queryString(searchCommand.getQuery().trim()
).toQuery();</code>.
     * <p/> Some other interesting options might be to add sorting to
the query,
     * adding other queries using a boolean query, or executing a
different
     * query.
     */
    protected CompassQuery buildQuery(CompassSearchCommand
searchCommand, CompassSession session) {
        return
session.queryBuilder().queryString(searchCommand.getQuery().trim()).toQu
ery();
    }

    /**
     * An option to perform any type of processing before the hits are
detached.
     */
    protected void doProcessBeforeDetach(CompassSearchCommand
searchCommand, CompassSession session, CompassHits hits,
                                         int from, int size) {

    }

    /**
     * An option to perform any type of processing before the hits are
detached.
     */
    protected void doProcessAfterDetach(CompassSearchCommand
searchCommand, CompassSession session,
                                        CompassDetachedHits hits) {

    }

    /**
     * Sets the page size for the pagination of the results. If not set,
not
     * pagination will be used.
     */
    public Integer getPageSize() {
        return pageSize;
    }

    /**
     * Returns the page size for the pagination of the results. If not
set, not
     * pagination will be used.
     *
     * @param pageSize
     */
    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }
}

10. Wire them up in faces-config.xml:

<managed-bean>
        <managed-bean-name>compassIndex</managed-bean-name>
        <managed-bean-class><<YOUR
PACKAGE>>.webapp.action.CompassIndex</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>

        <managed-property>
            <property-name>compassGps</property-name>
            <value>#{compassGps}</value>
        </managed-property>
    </managed-bean>

    <managed-bean>
        <managed-bean-name>compassSearch</managed-bean-name>
        <managed-bean-class><<YOUR
PACKAGE>>.webapp.action.CompassSearch</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>

        <managed-property>
            <property-name>compass</property-name>
            <value>#{compass}</value>
        </managed-property>

        <managed-property>
            <property-name>pageSize</property-name>
            <value>10</value>
        </managed-property>
    </managed-bean>

11. Create JSP's in web:

        a. reindex.jsp

<%@ include file="/common/taglibs.jsp"%>
<title>Compass Index</title>

<content tag="heading">Compass Index</content>
<f:view>
    <body>
    <f:verbatim>
       Use the Index button to index the database using Compass::Gps.
The operation will delete
       the current index and reindex the database based on the mappings
and devices defined in the
       Compass::Gps configuration context.
    </f:verbatim>
    <h:form id="compassIndexForm">
        <h:commandButton action="#{compassIndex.doIndex}"
value="Index"/>
    </h:form>
    <c:if test="${compassIndex.indexTime != 0}">
        <f:verbatim><P>Indexing took:</f:verbatim><c:out
value="${compassIndex.indexTime}" /><f:verbatim>ms.</f:verbatim>
    </c:if>
    </body>
</f:view>

        b. search.jsp

<%@ include file="/common/taglibs.jsp" %>
<title>Compass Search</title>

<content tag="heading">Compass Search</content>
<f:view>
    <body>
    <h:form id="compassSearchForm">
        <h:inputText id="query" size="20"
value="#{compassSearch.query}"/>
        <h:commandButton action="#{compassSearch.doSearch}"
value="Search"/>
    </h:form>
    <p/>
    <c:if test="${! empty compassSearch.searchResults}">
        <P/>
        Search took
        <c:out value="${compassSearch.searchResults.searchTime}"/>
        ms
        <P/>
        <h:dataTable var="hit"
value="#{compassSearch.searchResults.hits}" style="display:none"/>

        <display:table name="compassSearch.searchResults.hits"
cellspacing="0" cellpadding="0" requestURI=""
                       id="hit" pagesize="25" class="list"
export="true">

            <display:column title="Score">
                 <fmt:formatNumber type="percent" value="${hit.score}"/>
            </display:column>
            <display:column title="Type">
                <c:out value="${hit.alias}"/>
            </display:column>
            <display:column title="ID">
                        <c:out value="${hit.data.id}"/>
                </display:column>


            <display:setProperty name="paging.banner.item_name"
value="Item"/>
            <display:setProperty name="paging.banner.items_name"
value="Items"/>
        </display:table>
    </c:if>
    </body>
</f:view>

12. Add navigation rules in faces-config.xml:

<navigation-rule>
        <from-view-id>/*</from-view-id>
        <navigation-case>
            <from-outcome>indexComplete</from-outcome>
            <to-view-id>/reindex.jsp</to-view-id>
            <redirect/>
        </navigation-case>
    </navigation-rule>
    <navigation-rule>
        <from-view-id>/search.jsp</from-view-id>
        <navigation-case>
            <from-outcome>searchResults</from-outcome>
            <to-view-id>/search.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>

13. Add everything to the menu:

a. Add in menu - edit menu-config in web/WEB-INF add the reindex to
the admin menu:
<Item name="ReIndex" title="menu.reindex" page="/reindex.html"
roles="admin" />
b. add search to it's own menu:
        <Menu name="SearchMenu" title="menu.search" page="/search.html"
wifth="60" />
c. now edit /web/menu.jsp to add the new search menu:
<menu:displayMenu name="FileUpload"/>
<menu:displayMenu name="SearchMenu"/> <!--  ADDED LiNE -->
 <menu:displayMenu name="AdminMenu"/>
d. add the menu properties in
WEB-INF/classes/ApplicationResources.properties :
menu.search=Search
menu.reindex=Re-Index

Enjoy!

- Matt
matt.stine@...

> -----Original Message-----
> From: Matt Raible [mailto:mraible@...]
> Sent: Friday, July 07, 2006 9:50 AM
> To: users@...
> Subject: Re: [appfuse-user] search - integrate compass (lucene) and
> appfuse
>
> Thanks Matt!  You guys are going to have the 2.1 features done before
> we even get started on 2.0. ;-)
>
> Matt
>
> On 7/7/06, Stine, Matt <Matt.Stine@...> wrote:
> > Just wanted to let you guys know that I'm working on a JSF version
of
> > this tutorial.  Everything will be the same up until the point that
> > Spring MVC came into play.  I've basically pilfered the source of
the

> > Spring controllers and turned them into backing beans.  It works out
> > quite nicely.
> >
> > I'll post them up once they're working nicely.
> >
> > - Matt
> > matt.stine@...
> >
> > > -----Original Message-----
> > > From: chas66@... [mailto:chas66@...] On Behalf Of
Chris
> > Barham
> > > Sent: Monday, June 26, 2006 9:17 PM
> > > To: users@...
> > > Subject: Re: [appfuse-user] search - integrate compass (lucene)
and
> > > appfuse
> > >
> > > Hi Matt,
> > >
> > > Shay did a review over at the Compass forum and made some
suggestions.
> > >  I will rework and incorporate them.  Also, as I will have to do
this
> > > anyway, I will try to rework the Spring Controller to give a
> > > DisplayTag-able List and return the search hit highlight terms.
> > >
> > > Once done I'll repost.
> > >
> > > Shay's comments are at http://tinyurl.com/f9qm9  (which is
> > > http://forums.opensymphony.com/thread.jspa?threadID=35452&tstart=0
for
> > > those allergic to snipurl/tinurl :-) )
> > >
> > > Regards,
> > > Chris
> > >
> > >
> > >
> > > On 6/24/06, Matt Raible <mraible@...> wrote:
> > > > Great work Chris!  Thanks for the detailed instructions.
Hopefully
> > > > someone else can "tech review" them and we can get them on the
wiki,
> > > > or possibly published in an article on java.net.  If anyone is
> > > > interested in writing an article for java.net (or another site),
let

> > > > me know.  I can probably hook you up.
> > > >
> > > > Matt
> > > >
> > > > On 6/23/06, Chris Barham <cbarham@...> wrote:
> > > > > Hi,
> > > > >
> > > > > I've been playing with Compass and Appfuse to give search
> > capability.
> > > > > I made notes as I was going and post them here in case anyone
else
> > > > > finds them useful.  A big thanks to Matt and Shay for these
two
> > > > > projects, they work so well together :-)
> > > > >
> > > > > This is a barebones setup, my next job, (I think), is to
rework
> > the
> > > > > SpringController to give back a list with highlight terms on
the
> > > > > search results so that Displaytag can render it, (If anyone
has

> > done
> > > > > this please let me know if this is the best approach).
> > > > >
> > > > > Once running you can browse the index using Luke
> > > http://www.getopt.org/luke/
> > > > >
> > > > > Steps as follows:
> > > > >
> > > > > Integrate Compass search with Appfuse
> > > > > -----------------------------------------------------
> > > > >
> > > > > 1.      Get a new latest Appfuse project setup a la
> > > > > http://raibledesigns.com/wiki/AppFuseQuickStart.html  For this
I
> > used
> > > > > a project called weblogs, using Spring MVC and hibernate
(Apache

> > Derby
> > > > > as the RDBMS)
> > > > > 2.      Get Spring 2.0 (currently Rc1)
> > > http://www.springframework.org/download
> > > > > 3.      Get Compass (currently 0.9.2SNAPSHOT)
> > > http://www.opensymphony.com/compass/
> > > > > 4.      Install these...
> > > > > a.      Make directories under lib directory place jars as
> > follows:
> > > > >
> > > > > compass-0.9.2-SNAPSHOT
> > > > > |-- commons-logging.jar
> > > > > |-- compass.jar
> > > > > |-- lucene-analyzers.jar
> > > > > |-- lucene-core.jar
> > > > > |-- lucene-highlighter.jar
> > > > > `-- lucene-snowball.jar
> > > > >
> > > > > and
> > > > >
> > > > > spring-2.0RC1/
> > > > > |-- acegi-security-1.0.0-RC2.jar
> > > > > |-- commons-codec-1.3.jar
> > > > > |-- ehcache-1.2.jar
> > > > > |-- spring-aspects.jar
> > > > > |-- spring-mock.jar
> > > > > |-- spring.jar
> > > > > |-- springmodules-validator-dev-20051217.jar
> > > > > `-- validator-rules.xml
> > > > >
> > > > >
> > > > > b.      Change lib.properties:
> > > > >
> > > > > #
> > > > > # Spring Framework - http://www.springframework.org
> > > > > #
> > > > > spring.version=2.0RC1
> > > > > spring.dir=${lib.dir}/spring-${spring.version}
> > > > > spring.jar=${spring.dir}/spring.jar
> > > > >
> > > > > #
> > > > > # Compass search http://www.opensymphony.com/compass/
> > > > > #
> > > > > compass.version=0.9.2-SNAPSHOT
> > > > > compass.dir=${lib.dir}/compass-${compass.version}
> > > > >
> > > > > 5.      Add compass to the service.compile.classpath and
> > > > > web.compile.classpath in properties.xml:
> > > > >         <fileset dir="${compass.dir}" includes="*.jar" />
> > > > > 6.      Add the compass jars to the war task in build.xml (so
they
> > get
> > > > > copied into the war)
> > > > >          <lib dir="${compass.dir}" includes="*.jar"/>
> > > > > 7.      Add the metadata files to src/dao/../model/
> > > > > Weblogs.cmd.xml - common metadata (optional) - this doesn't
get
> > used
> > > > > in this example
> > > > > E.g.:
> > > > > <?xml version="1.0"?>
> > > > > <!DOCTYPE compass-core-meta-data PUBLIC
> > > > >     "-//Compass/Compass Core Meta Data DTD 1.0//EN"
> > > > >
"http://www.opensymphony.com/compass/dtd/compass-core-meta-
> > > data.dtd">
> > > > >
> > > > > <compass-core-meta-data>
> > > > >         <meta-data-group id="weblogs" displayName="Weblogs
Meta

> > Data">
> > > > >                 <description>mongoose Meta Data</description>
> > > > >                  <uri>http://compass/weblogs</uri>
> > > > >                 <meta-data id="createddate"
> > displayName="createddate">
> > > > >                         <description>CreatedDate</description>
> > > > >
> > <uri>http://compass/weblogs/createddate</uri>
> > > > >                         <name
> > format="dd/MM/yyyy">createddate</name>
> > > > >                 </meta-data>
> > > > >         </meta-data-group>
> > > > > </compass-core-meta-data>
> > > > >
> > > > >
> > > > > Mapping metadata: weblogs.cpm.xml
> > > > >
> > > > > <?xml version="1.0"?>
> > > > > <!DOCTYPE compass-core-mapping PUBLIC
> > > > >     "-//Compass/Compass Core Mapping DTD 1.0//EN"
> > > > >     "http://www.opensymphony.com/compass/dtd/compass-core-
> > > mapping.dtd">
> > > > >
> > > > > <compass-core-mapping package="com.pobox.cbarham.model">
> > > > >         <!-- ============================================= -->
> > > > >         <!--  USER           -->
> > > > >         <!-- ============================================= -->
> > > > >         <class name="User" alias="user" root="true">
> > > > >                 <id name="id" />
> > > > >                 <constant>
> > > > >                         <meta-data>type</meta-data>
> > > > >
<meta-data-value>user</meta-data-value>
> > > > >                 </constant>
> > > > >                 <property name="lastName">
> > > > >                         <meta-data
boost="2">lastName</meta-data>

> > > > >                 </property>
> > > > >                 <property name="firstName">
> > > > >                         <meta-data>firstName</meta-data>
> > > > >                 </property>
> > > > >                 <property name="enabled">
> > > > >                         <meta-data>enabled</meta-data>
> > > > >                 </property>
> > > > >                 <property name="phoneNumber">
> > > > >                         <meta-data>phoneNumber</meta-data>
> > > > >                 </property>
> > > > >                 <property name="email">
> > > > >                         <meta-data>email</meta-data>
> > > > >                 </property>
> > > > >                 <property name="address">
> > > > >                         <meta-data>address</meta-data>
> > > > >                 </property>
> > > > >                 <property name="email">
> > > > >                         <meta-data>email</meta-data>
> > > > >                 </property>
> > > > >                 <property name="accountExpired">
> > > > >                         <meta-data>accountExpired</meta-data>
> > > > >                 </property>
> > > > >                 <property name="accountLocked">
> > > > >                         <meta-data>accountLocked</meta-data>
> > > > >                 </property>
> > > > >                 <property name="username">
> > > > >                         <meta-data>username</meta-data>
> > > > >                 </property>
> > > > >                 <property name="website">
> > > > >                         <meta-data>website</meta-data>
> > > > >                 </property>
> > > > >
> > > > >                 <component name="roles" ref-alias="role" />
> > > > >                 <component name="address" ref-alias="address"
/>
> > > > >         </class>
> > > > >         <!-- ============================================= -->
> > > > >         <!--  ROLE            -->
> > > > >         <!-- ============================================= -->
> > > > >         <class name="Role" alias="role" root="false">
> > > > >                 <id name="id" />
> > > > >                 <constant>
> > > > >                         <meta-data>type</meta-data>
> > > > >
<meta-data-value>role</meta-data-value>

> > > > >                 </constant>
> > > > >                 <property name="description">
> > > > >                         <meta-data>description</meta-data>
> > > > >                 </property>
> > > > >                 <property name="name">
> > > > >                         <meta-data>name</meta-data>
> > > > >                 </property>
> > > > >         </class>
> > > > >         <!-- ============================================= -->
> > > > >         <!--  ADDRESS            -->
> > > > >         <!-- ============================================= -->
> > > > >         <class name="Address" alias="address" root="false">
> > > > >                 <constant>
> > > > >                         <meta-data>type</meta-data>
> > > > >
<meta-data-value>address</meta-data-value>

> > > > >                 </constant>
> > > > >                 <property name="address">
> > > > >                         <meta-data>address</meta-data>
> > > > >                 </property>
> > > > >                 <property name="city">
> > > > >                         <meta-data>address</meta-data>
> > > > >                 </property>
> > > > >                 <property name="country">
> > > > >                         <meta-data>address</meta-data>
> > > > >                 </property>
> > > > >                 <property name="postalCode">
> > > > >                         <meta-data>address</meta-data>
> > > > >                 </property>
> > > > >                 <property name="province">
> > > > >                         <meta-data>address</meta-data>
> > > > >                 </property>
> > > > >         </class>
> > > > >
> > > > > </compass-core-mapping>
> > > > >
> > > > > 8.      Edit
> > src/service/.../service/applicationContext-service.xml
> > > > >  And add the compass spring beans: (change the resource
locations
> > > > > accordingly) - also note that this puts the index on the root
> > > > > filesystem in a directory called compass
> > > > >
> > > > >         <!-- COMPASS START -->
> > > > >         <bean id="compass"
> > > class="org.compass.spring.LocalCompassBean">
> > > > >                 <property name="resourceLocations">
> > > > >                         <list>
> > > > >
<value>classpath:{PATH-TO-MODEL}
> > > /model/weblogs.cmd.xml</value>
> > > > >                                 <value>classpath:
:{PATH-TO-MODEL

> > > /model/weblogs.cpm.xml</value>
> > > > >                         </list>
> > > > >                 </property>
> > > > >                 <property name="compassSettings">
> > > > >                         <props>
> > > > >                                 <prop
> > > key="compass.engine.connection">file:///compass/weblogs</prop>
> > > > >                                 <prop
> > >
> >
key="compass.transaction.factory">org.compass.spring.transaction.SpringS

> > yn
> > > cTransactionFactory</prop>
> > > > >                         </props>
> > > > >                 </property>
> > > > >                 <property name="transactionManager"
> > > ref="transactionManager" />
> > > > >         </bean>
> > > > >         <bean id="hibernateGpsDevice"
> > > > >
> >
class="org.compass.spring.device.hibernate.SpringHibernate3GpsDevice">

> > > > >                 <property name="name">
> > > > >                         <value>hibernateDevice</value>
> > > > >                 </property>
> > > > >                 <property name="sessionFactory"
> > ref="sessionFactory"
> > > />
> > > > >
> > > > >         </bean>
> > > > >         <bean id="compassGps"
> > > class="org.compass.gps.impl.SingleCompassGps"
> > > > > init-method="start" destroy-method="stop">
> > > > >                 <property name="compass">
> > > > >                         <ref bean="compass" />
> > > > >                 </property>
> > > > >                 <property name="gpsDevices">
> > > > >                         <list>
> > > > >                                 <bean
> > >
> >
class="org.compass.spring.device.SpringSyncTransactionGpsDeviceWrapper">
> > > > >                                         <property
name="gpsDevice"

> > > ref="hibernateGpsDevice" />
> > > > >                                 </bean>
> > > > >                         </list>
> > > > >                 </property>
> > > > >         </bean>
> > > > >         <!-- COMPASS END -->
> > > > >
> > > > > 9.      Add in the JSP's to drive the index and search....
> > > > > a.       Under web/pages add a reindex.jsp:
> > > > > <%@ include file="/common/taglibs.jsp"%>
> > > > > <P>
> > > > > <H2>Compass Index</H2>
> > > > > <P>
> > > > > Use the Index button to index the database using Compass::Gps.
The
> > > > > operation will
> > > > > delete the current index and reindex the database based on the
> > > > > mappings and devices
> > > > > defined in the Compass::Gps configuration context.
> > > > > <FORM method="POST" action="<c:url value="/reindex.html"/>">
> > > > >         <spring:bind path="command.doIndex">
> > > > >                 <INPUT type="hidden" name="doIndex"
value="true"
> > />
> > > > >         </spring:bind>
> > > > >     <INPUT type="submit" value="Index"/>
> > > > > </FORM>
> > > > > <c:if test="${! empty indexResults}">
> > > > >         <P>Indexing took: <c:out
value="${indexResults.indexTime}"

> > > />ms.
> > > > > </c:if>
> > > > > <P>
> > > > >
> > > > > b.      under web/pages add search.jsp:
> > > > > <%@ include file="/common/taglibs.jsp"%>
> > > > > <title>Search</title>
> > > > > <content tag="heading">
> > > > > Search:
> > > > > </content>
> > > > > <FORM method="GET">
> > > > >         <spring:bind path="command.query">
> > > > >                 <INPUT type="text" size="20" name="query"
> > > value="<c:out
> > > > > value="${status.value}"/> " />
> > > > >         </spring:bind>
> > > > >
> > > > >         <P />
> > > > >                 <INPUT type="submit" value="Search" />
> > > > > </FORM>
> > > > > <p />
> > > > >         <c:if test="${! empty searchResults}">
> > > > >                 <P />
> > > > >                         Search took
> > > > >                         <c:out
value="${searchResults.searchTime}"

> > />
> > > > >                         ms
> > > > >                 <P />
> > > > >                 <TABLE border="2">
> > > > >                         <TR>
> > > > >                                 <TH>
> > > > >                                         SCORE
> > > > >                                 </TH>
> > > > >                                 <TH>
> > > > >                                         TYPE
> > > > >                                 </TH>
> > > > >                                 <TH>
> > > > >                                         ID
> > > > >                                 </TH>
> > > > >                         </TR>
> > > > >
> > > > >                         <c:forEach var="hit"
> > > items="${searchResults.hits}">
> > > > >                                 <P />
> > > > >                                 <TR>
> > > > >                                         <TD>
> > > > >
<fmt:formatNumber

> > > type="percent" value="${hit.score}" />
> > > > >                                         </TD>
> > > > >                                         <TD>
> > > > >                                                 <c:out
> > > value="${hit.alias}" />
> > > > >
> > > > >                                         </TD>
> > > > >                                         <TD>
> > > > >                                                 <c:out
> > > value="${hit.data.id}" />
> > > > >                                         </TD>
> > > > >                                 </TR>
> > > > >                         </c:forEach>
> > > > >                 </TABLE>
> > > > >
> > > > >         </c:if>
> > > > >
> > > > > c.      Wire up the controllers - edit
> > web/WEB-INF/action-servlet.xml
> > > and
> > > > > add these beans:
> > > > >
> > > > >         <bean id="searchController"
> > > > > class="org.compass.spring.web.mvc.CompassSearchController">
> > > > >                 <property name="compass"><ref
> > > bean="compass"/></property>
> > > > >                 <property
> > > name="searchView"><value>searchView</value></property>
> > > > >                 <property
> > >
name="searchResultsView"><value>searchResultsView</value></property>

> > > > >                 <property
> > name="pageSize"><value>10</value></property>
> > > > >         </bean>
> > > > >         <!-- ====  COMPASS SEARCH CONTROLLER ==== -->
> > > > >
> > > > >         <bean id="indexController"
> > > > > class="org.compass.spring.web.mvc.CompassIndexController">
> > > > >                 <property name="compassGps"><ref
> > > bean="compassGps"/></property>
> > > > >                 <property
> > > name="indexView"><value>reindexView</value></property>
> > > > >                 <property
> > >
name="indexResultsView"><value>reindexResultsView</value></property>
> > > > >         </bean>
> > > > >
> > > > >     <!-- View Resolver for JSPs -->
> > > > >         <bean id="rbViewResolver"
> > > > >
> > >
> >
class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
> > > > >                 <property
> > > name="basename"><value>views</value></property>
> > > > >                 <property
name="order"><value>0</value></property>

> > > > >         </bean>
> > > > > d.      Also add them into the urlMapping:
> > > > >         <prop key="/search.html">searchController</prop>
> > > > > <prop key="/reindex.html">indexController</prop>
> > > > >
> > > > > e.      Add a file views.properties under web/WEB-INF/classes
> > > containing:
> > > > > searchView.class=org.springframework.web.servlet.view.JstlView
> > > > > searchView.url=/WEB-INF/pages/search.jsp
> > > > >
> > > > >
> >
searchResultsView.class=org.springframework.web.servlet.view.JstlView
> > > > > searchResultsView.url=/WEB-INF/pages/search.jsp
> > > > >
> > > > >
reindexView.class=org.springframework.web.servlet.view.JstlView
> > > > > reindexView.url=/WEB-INF/pages/reindex.jsp
> > > > >
> > > > >
> >
reindexResultsView.class=org.springframework.web.servlet.view.JstlView

> > > > > reindexResultsView.url=/WEB-INF/pages/reindex.jsp
> > > > >
> > > > > f.      Add in menu - edit menu-config in web/WEB-INF add the
> > reindex
> > > to
> > > > > the admin menu:
> > > > > <Item name="ReIndex" title="menu.reindex" page="/reindex.html"
> > > roles="admin" />
> > > > > g.      add search to it's own menu:
> > > > >         <Menu name="SearchMenu" title="menu.search"
> > > page="/search.html" wifth="60" />
> > > > > h.      now edit /web/pages/menu/jsp to add the new search
menu:

> > > > > <menu:displayMenu name="FileUpload"/>
> > > > > <menu:displayMenu name="SearchMenu"/> <!--  ADDED LiNE -->
> > > > >  <menu:displayMenu name="AdminMenu"/>
> > > > > i.      add the menu properties in
> > > > > WEB-INF/classes/ApplicationResources.properties :
> > > > > menu.search=Search
> > > > > menu.reindex=Re-Index
> > > > >
> > > > >
> > > > > Cheers
> > > > > Chris
> > > > >
> > > > > --
> > > > > -------------------------------------------------
> > > > > Christopher Barham
> > > > > cbarham@...
> > > > >
> > > > >
> >
---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: users-unsubscribe@...
> > > > > For additional commands, e-mail:
users-help@...
> > > > >
> > > > >
> > > >
> > > >
> >
---------------------------------------------------------------------

> > > > To unsubscribe, e-mail: users-unsubscribe@...
> > > > For additional commands, e-mail: users-help@...
> > > >
> > > >
> > > >
> > >
> > >
> > > --
> > > -------------------------------------------------
> > > Christopher Barham
> > > cbarham@...
> > >
> > >
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@...
> > > For additional commands, e-mail: users-help@...
> > >
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@...
> > For additional commands, e-mail: users-help@...
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...

 « Return to Thread: RE: search - integrate compass (lucene) and appfuse