[opencms-dev] Solr Query

Daniel Seidel d.seidel at alkacon.com
Tue May 31 08:34:11 CEST 2022


Hi,


you are using the wrong Solr field. If you map use


<solrfield targetfield="contentdate" sourcefield="*_dt"/>


your field names will be "contentdate_{locale}_dt".


If you use a recent version of OpenCms, I'll recommend using the 
fieldsettings syntax 
(https://documentation.opencms.org/opencms-documentation/content-in-opencms/defining-a-content-type/defining-the-contents-behavior/field-settings/index.html) 
for the mapping and with "listdate" 
(https://documentation.opencms.org/opencms-documentation/content-in-opencms/defining-a-content-type/defining-the-contents-behavior/search-settings/index.html#short-cut-syntax-for-the-most-relevant-search-settings).


Probably the date field will also be the best field for sorting.


Best, Daniel.



Am 31.05.22 um 08:23 schrieb Диканский Андрей Юрьевич via opencms-dev:
>
> Hello, All!
>
>
> I need to select some news and output JSON.
>
>
> I have following code in my News schema:
>
>
> <xsd:complexType name="OpenCmsEnNews">
> <xsd:sequence>
> <xsd:element name="Title" type="OpenCmsString"/>
> <xsd:element name="ShortDescription" type="OpenCmsString"/>
> <xsd:element name="ImagePreview" type="OpenCmsVfsFile"/>
> <xsd:element name="Date" type="OpenCmsDateTime"/>
> <xsd:element name="FullDescription" type="OpenCmsHtml"/>
> <xsd:element name="Category" type="OpenCmsCategory"/>
> <xsd:element name="PublishTime" type="OpenCmsPublishTime" minOccurs="0"/>
> </xsd:sequence>
> <xsd:attribute name="language" type="OpenCmsLocale" use="required"/>
> </xsd:complexType>
>
>
> <searchsettings containerPageOnly="false">
>         <searchsetting element="Date" searchcontent="false">
>           <solrfield targetfield="contentdate" sourcefield="*_dt"/>
>         </searchsetting>
>
>
> I made solr query like this:
>
>
> <c:set var="searchPath">${cms.requestContext.siteRoot}/</c:set>
> <c:set var="cat" value="${param.cat}" />
> <c:set var="start" value="${param.start}" />
> <c:set var="end" value="${param.end}" />
> <c:set var='solrNewsQuery'>
> {
> "core" : "Solr Online",
> "ignorequery" : true,
> "ignoreReleaseDate" : false,
> "ignoreExpirationDate" : false,
> "queryparam" : ":",
> "escapequerychars" : true,
> "extrasolrparams" : 
> "fq=parent-folders:\"${searchPath}\"&fq=type:EnNews&fq=category:${cat}&fq=contentdate:[${start}T00:00:00Z 
> TO ${end}T23:59:59Z]&sort=Newsdate_prop desc",
> "pagesize" : "3000",
> }
> </c:set>
> <cms:search configString="${solrNewsQuery}" var="search" 
> addContentInfo="true" />
> [
> <c:forEach var="news" items="${search.searchResults}" varStatus="status">
> .....
>
>
>
> I made a query with certain period of data and expect a list of news. 
> But some news are missing in output. If I change in 
> extrasolrparams "contentdate" to "created" then missing news are 
> presented in output.
>
> But it is convinient for me to get news by Date property not by 
> created attribute.
>
>
> I guess the problem is in indexing Date property. I tried to publish 
> again missed news, but nothig changed.
>
>
> Can any one help me with selecting news by Date property?
>
>
>
> _______________________________________________
> 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
> https://lists.opencms.org/mailman/listinfo/opencms-dev
>
>
>
-- 
Kind Regards

Daniel.

-------------------

Daniel Seidel
Alkacon Software GmbH & Co. KG - The OpenCms Experts
https://www.alkacon.com  -http://www.opencms.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opencms.org/pipermail/opencms-dev/attachments/20220531/d68a74c1/attachment.htm>


More information about the opencms-dev mailing list