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

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


Hi Rüdiger,

I think that's why:

public class CmsXmlDateTimeValue extends A_CmsXmlValueTextBase {
.
.
.
.
    public boolean isSearchable() {

        // there is no point in searching date/time values
        // they are stored as long int anyway
        return false;
    }
.
.
.

But even changing this and compiling etc. as well as setting explicit search
annotation in the xsd, doesn't change the behavior.
The field value is not to be found in the extractionResult.

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




More information about the opencms-dev mailing list