[opencms-dev] Lucene date range search in individual xmlContent date fields

] Code Create [ Bernd Wolfsegger ocms at code-create.de
Wed May 23 11:22:25 CEST 2012


Hi Rüdiger,

what a crude stuff ;-))

But it works like a charm now :-)

Though, first I had to rewrite all the contents so that the mapping takes
place.

It's not important, but is there any known reason, why it is not possible to
get the value of the field with the long (the xml content date field) as
part of the extraction content?

Is it because the long is not considered to have any sound or useful textual
representation :)

public class CmsDocumentXmlContent extends A_CmsVfsDocument {
.
.
.
	
/**
 * String org.opencms.xml.types.I_CmsXmlContentValue.getPlainText(CmsObject
cms)
 * Returns the value of this XML content node as a plain text String.
 *
 * Plain text in this context means a pure textual representation of the
content (i.e. without html tags).
 * The plain text may be null, too, if there is no sound or useful textual
representation (i.e. color values).
 *
 *
 * Parameters:
 * cms an initialized instance of a CmsObject
 * Returns:
 * the value of this XML content node as a plain text String
*/

String extracted = value.getPlainText(cms);

.
.
.

Anyway, thanx a lot!

Kind regards, Bernd


> -----Ursprüngliche Nachricht-----
> Von: "Rüdiger Kurz (list)" [mailto:r.kurz at alkacon.com]
> Gesendet: Mittwoch, 23. Mai 2012 09:28
> An: ocms at code-create.de; The OpenCms mailing list
> Betreff: Re: [opencms-dev] Lucene date range search in individual
> xmlContent date fields
> 
> Hi Bernd,
> 
> the extraction result is created in CmsDocumentXmlContent
> 
> https://github.com/alkacon/opencms-
> core/blob/branch_7_5_x/src/org/opencms/search/documents/CmsDocumentXmlC
> ontent.java#L123
> 
> but my suggestion would be to map your date to a property. This is done
> in the appinfo node of the schema of your XML content e.g.:
> <mapping element="MyDate" mapto="property:myDate" />
> 
> Then, as you can see the method
> 
> String getStringValue(
>            CmsObject cms,
>            CmsResource res,
>            I_CmsExtractionResult extractionResult,
>            List<CmsProperty>  properties,
>            List<CmsProperty>  propertiesSearched) {
> 
> in CmsSearchFieldMapping - which you have already implemented -
> presents
> you a List of properties ...
> 
> good luck
> Rüdiger
> 
> 
> On 05/22/2012 11:02 PM, ] Code Create [ Bernd Wolfsegger wrote:
> > Hi Rüdiger,
> >
> > well, unfortunately "extractionResult" does not contain the value of
> my xml
> > content "date" field.
> > It's just a number in that field in the raw xml, so it seems numbers
> are not
> > included in the " extractionResult".
> > Do I have to the pick the field value from a byte array via CmsObject
> ->
> > CmsFile ? :-)
> > Or are there simpler means?
> > Is there another class to extend so "number" values are included?
> >
> > Kind regards, Bernd
> >
> >> -----Ursprüngliche Nachricht-----
> >> Von: "Rüdiger Kurz (list)" [mailto:r.kurz at alkacon.com]
> >> Gesendet: Dienstag, 22. Mai 2012 19:18
> >> An: ocms at code-create.de; The OpenCms mailing list
> >> Betreff: Re: [opencms-dev] Lucene date range search in individual
> >> xmlContent date fields
> >>
> >> Hi Bernd,
> >>
> >> OpenCms 7.5.x supports the configuration of field mappings that is
> done
> >> in the opencms-search.xml. If you add a field mapping like:
> >>
> >> <field name="my_date" store="true" index="true">
> >> <mapping type="dynamic"
> >> class="example.MyFieldMapping">my_date</mapping>
> >> </field>
> >>
> >> you are able to create a class that extends CmsSearchFieldMapping
> and
> >> overwrite the method getStringValue:
> >>
> >> https://github.com/alkacon/opencms-
> >>
> core/blob/branch_7_5_x/src/org/opencms/search/fields/CmsSearchFieldMapp
> >> ing.java#L141
> >>
> >> String getStringValue(
> >>           CmsObject cms,
> >>           CmsResource res,
> >>           I_CmsExtractionResult extractionResult,
> >>           List<CmsProperty>  properties,
> >>           List<CmsProperty>  propertiesSearched) {
> >>
> >>       // for example write something like:
> >>
> >>       String result = null;
> >>       if (getType().getMode()
> >>           == CmsSearchFieldMappingType.DYNAMIC.getMode()
> >>          &&  "my_date".equals(getParam())) {
> >>
> >>           // do your special date mapping here
> >>           // Generate date terms for optimized date range search.
> >>           // @see CmsLuceneIndex#getDateRangeSpan(long, long)
> >>           // *** return the String representation of that terms ***
> >>       }
> >>       return super.getStringValue(
> >>           cms,
> >>           res,
> >>           extractionResult,
> >>           properties,
> >>           propertiesSearched);
> >> }
> >>
> >> *** return the String representation of that terms ***
> >> maybe this utility method from OpenCms v8 is interesting for you:
> >>
> >> https://github.com/alkacon/opencms-
> >>
> core/blob/master/src/org/opencms/search/fields/CmsSearchFieldConfigurat
> >> ion.java#L132
> >>
> >> I know this is really concrete but anyway I hope that it will give
> you
> >> a
> >> hand...
> >>
> >> regards
> >> Rüdiger
> >>
> >> On 05/22/2012 06:34 PM, ] Code Create [ Bernd Wolfsegger wrote:
> >>> Hi Rüdiger,
> >>>
> >>> thanx for your answer.
> >>>
> >>> As I understood it, Lucene (up to version 2.9) range search is only
> >> done
> >>> lexographically, so date values have to be saved in the index in a
> >> string
> >>> format like "yyyyMMddHHmmss".
> >>> Search itself is handled by lucene then.
> >>> So does OpenCms store its "date" xml content values (as defined in
> an
> >> xml
> >>> content schema) that way in the index when mapped for a file via
> the
> >> field
> >>> configuration?
> >>> Or do you have to write that extra lines of Java classes for this
> >> purpose :)
> >>>
> >>> Is there a difference between OpenCms 7.5.x and 8.0.x in that
> matter?
> >> Lucene
> >>> 2.9 and up is capable of handling other than String data.
> >>>
> >>> By the way. I don't want to restrict my search to date values. I'd
> >> like to
> >>> include search for dates and date ranges transparently with
> searching
> >> in
> >>> other text fields.
> >>>
> >>> So one is able to search by: "mydate:[201205 TO 201206]"
> >>> As well as: "some other searchterm"
> >>>
> >>> Kind regards, Bernd
> >>>
> >>>
> >>>> -----Ursprüngliche Nachricht-----
> >>>> Von: "Rüdiger Kurz (list)" [mailto:r.kurz at alkacon.com]
> >>>> Gesendet: Dienstag, 22. Mai 2012 16:51
> >>>> An: ocms at code-create.de; The OpenCms mailing list
> >>>> Betreff: Re: [opencms-dev] Lucene date range search in individual
> >>>> xmlContent date fields
> >>>>
> >>>> Hi,
> >>>>
> >>>> performance is the reason for not using "long" values to search
> for
> >>>> date
> >>>> ranges.
> >>>>
> >>>> If you want to restrict your search based on an individual dates
> >>>> specified in a schema of an XML content. You don't come along
> >> writing
> >>>> some lines of Java classes, compile them and put them into the
> class
> >>>> path of the servlet container.
> >>>>
> >>>> Please let me know, if this would be a possibility for you.
> >>>>
> >>>> greetings
> >>>> Rüdiger
> >>>>
> >>>> On 05/22/2012 04:36 PM, ] Code Create [ Bernd Wolfsegger wrote:
> >>>>> Hi,
> >>>>>
> >>>>> does anyone know how to accomplish this, if it is possible at
> all?
> >>>>> I have no problem searching with a query like: "created:[201205
> TO
> >>>> 201206]"
> >>>>> But how do I configure fields to search in for my own specific
> xml-
> >>>> content
> >>>>> date fields?
> >>>>> I tried a field configuration where I mapped an xml-content date
> >>>> field, but
> >>>>> I didn't get any results in the search.
> >>>>> I'm using the Lucene Snowball analyzer (2.4.1)
> >>>>>
> >>>>> Anyone tried similar stuff ? :-)
> >>>>>
> >>>>> Thanx for any hints.
> >>>>>
> >>>>> Still using OpenCms 7.5.1
> >>>>>
> >>>>>
> >>>>> Kind regards, Bernd
> >>>>>
> >>>>> _______________________________________________
> >>>>> This mail is sent to you from the opencms-dev mailing list
> >>>>> To change your list options, or to unsubscribe from the list,
> >> please
> >>>> visit
> >>>>> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
> >>>>>
> >>>>>
> >>>>>
> >>>>
> >>>> --
> >>>> Kind Regards,
> >>>> Rüdiger.
> >>>>
> >>>> -------------------
> >>>>
> >>>> Visit OpenCms Days 2012 Conference and Expo September 24 to 25,
> 2012
> >> in
> >>>> Cologne, Germany http://www.opencms-days.org
> >>>>
> >>>> Rüdiger Kurz
> >>>>
> >>>> Alkacon Software GmbH  - The OpenCms Experts
> >>>> http://www.alkacon.com - http://www.opencms.org
> >>>
> >>> _______________________________________________
> >>> This mail is sent to you from the opencms-dev mailing list
> >>> To change your list options, or to unsubscribe from the list,
> please
> >> visit
> >>> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
> >>>
> >>>
> >>>
> >>
> >> --
> >> Kind Regards,
> >> Rüdiger.
> >>
> >> -------------------
> >>
> >> Visit OpenCms Days 2012 Conference and Expo September 24 to 25, 2012
> in
> >> Cologne, Germany http://www.opencms-days.org
> >>
> >> Rüdiger Kurz
> >>
> >> Alkacon Software GmbH  - The OpenCms Experts
> >> http://www.alkacon.com - http://www.opencms.org
> >
> > _______________________________________________
> > This mail is sent to you from the opencms-dev mailing list
> > To change your list options, or to unsubscribe from the list, please
> visit
> > http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
> >
> >
> >
> 
> --
> Kind Regards,
> Rüdiger.
> 
> -------------------
> 
> Visit OpenCms Days 2012 Conference and Expo September 24 to 25, 2012 in
> Cologne, Germany http://www.opencms-days.org
> 
> Rüdiger Kurz
> 
> Alkacon Software GmbH  - The OpenCms Experts
> http://www.alkacon.com - http://www.opencms.org




More information about the opencms-dev mailing list