[opencms-dev] Search in field of structured content

Steve Bryan steve at bright-interactive.com
Thu Sep 24 11:01:56 CEST 2009


Some more detail on how to search in structured field:

Config can be done via the OpenCms workplace in Administration view, or
direct in opencms-search.xml

 

You need to 

1. Create a search index and an associated index source. The source defines
the area of your website that is indexed, and the index maps on to a folder
where the Lucene search indexes are stored. 

http://www.applecentreorchard.com/moby/cms/alkacon-documentation/documentati
on_search/search_howto.html

 

Your source will need to include XML type ('xmlcontent').

 

eg - in my site I allow search over a Holiday XML type, that is contained in
a folder with path /sites/dtw/metadata/holiday/.

 

            <index>

                <name>Holiday</name>

                <rebuild>auto</rebuild>

                <project>Online</project>

                <locale>en</locale>

                <configuration>holiday</configuration>

                <sources>

                    <source>Holidays</source>

                </sources>

            </index>

            <indexsource>

                <name>Holidays</name>

                <indexer class="org.opencms.search.CmsVfsIndexer"/>

                <resources>

                    <resource>/sites/dtw/metadata/holiday/</resource>

                </resources>

                <documenttypes-indexed>

                    <name>xmlcontent</name>

                </documenttypes-indexed>

            </indexsource>

 

 

2. Notice the element <configuration>holiday</configuration> in the <index>
tag. This tells the index to use field mappings.

 

            <fieldconfiguration>

                <name>holiday</name>

                <fields> 

                    <field name="Title" store="true" index="false">

                        <mapping type="item">Title[1]</mapping>

                    </field>

                    <field name="SortTitle" store="true"
index="untokenized">

                        <mapping type="item">Title[1]</mapping>

                    </field>

                    <field name="Price" store="true" index="true">

                        <mapping type="item">Price[1]</mapping>

                    </field>

                    <field name="Duration" store="true" index="true">

                        <mapping type="item">Duration[1]</mapping>

                    </field>

                    <field name="Image" store="true" index="false">

                        <mapping type="property">image</mapping>

                    </field>

                </fields>

            </fieldconfiguration>

 

This store="true" means I can read the field in the results, and
index="true" means it is available to search on. I sort the results on
"SortTitle".

mapping type="item" maps elements to lucene fields.

mapping type="property" maps properties of the xml files (I have an image
property set on the xml objects externally).

 

 

Here's my holiday schema:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">

          

          <xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/>  

 

          <xsd:element name="Holidays" type="OpenCmsHolidays"/>

          

          <xsd:complexType name="OpenCmsHolidays">

                   <xsd:sequence>

                             <xsd:element name="Holiday"
type="OpenCmsHoliday" minOccurs="0" maxOccurs="unbounded"/>

                   </xsd:sequence>

          </xsd:complexType>

 

          <xsd:complexType name="OpenCmsHoliday">

                   <xsd:sequence>

                             <xsd:element name="Title" type="OpenCmsString"
/>

                             <xsd:element name="Duration"
type="OpenCmsString" />

                             <xsd:element name="Price" type="OpenCmsString"
/>

                   </xsd:sequence>

                   <xsd:attribute name="language" type="OpenCmsLocale"
use="required"/>

          </xsd:complexType>

 

          <xsd:annotation> 

                   <xsd:appinfo> 

                             <resourcebundle
name="com.bright.dtw.workplace"/> 

                             <mappings>

                                      <mapping element="Title"
mapto="property:Title" />

                             </mappings>

                             <validationrules>

                                      <rule element="Price" regex="[0-9]*"
message="Price should be a number." />

                             </validationrules>     

                   </xsd:appinfo> 

          </xsd:annotation>  

</xsd:schema>

 

 

 

3. You can search over the index using the OpenCms search API, something
like this to search on Price=50:

sQuery = "Price: 50";

                   CmsSearch search = new CmsSearch();

                   search.setIndex("Holiday");

                   search.setDisplayPages(k_iMaxPages);

                   search.setMatchesPerPage(iNumResults);

                   search.setSearchPage(iPage);

                   

                   Sort sort = new Sort("SortTitle");

                   search.setSortOrder(sort);

 

                   search.init(cmsObject);                          

                   search.setQuery(sQuery);                       

                   results = search.getSearchResult();

 

etc

 

Search on Google for 'Lucene query syntax' to find more detail on how to
form the query string in your search code.

 


-----Original Message-----

Date: Tue, 22 Sep 2009 13:23:32 +0100
From: "Steve Bryan" <steve at bright-interactive.com>
Subject: Re: [opencms-dev] Search in field of structured content
To: <opencms-dev at opencms.org>
Message-ID: <4ab8c1c5.1c05d00a.32fc.51ad at mx.google.com>
Content-Type: text/plain;	charset="US-ASCII"


Hi

You need to map the elements of the structured content item to Lucene
fields, using OpenCms search field configuration.

alkacon-documentation/documentation_search/configuration_fields.html

The configuration can be done in Administration > Search option, or see the
config file opencms-search.xml.

Steve

-----Original Message-----

Date: Mon, 21 Sep 2009 03:28:24 -0700 (PDT)
From: vespucio <sotormcf at gmail.com>
Subject: [opencms-dev]  Search in field of structured
	content....how??????
To: opencms-dev at opencms.org
Message-ID: <25530277.post at talk.nabble.com>
Content-Type: text/plain; charset=us-ascii


I have a problem...i dont know how to do an advanced search by a field of a
structured content....
for example, i have a structured content : New , and the new has a field :
EndDate....and i want to search by that date (not creation date of the file)
Please help me...im going crazy







More information about the opencms-dev mailing list