我正在使用solr4.7与 CoreContainer 创建核心,使用 EmbeddedSolrServer 进行连接,并使用 ModifiableSolrParams 来获取数据..
我已使用requestHelper
“import”配置“solrconfig.xml ”以导入数据配置的数据和其他配置文件,如下所示....
<dataConfig>
<dataSource driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/koupon"
user="root"
password="root" />
<document>
<entity name="koupon"
query="SELECT k.kouponid as kid, k.name, k.image,k.description,k.discount as discount,
k.startdate,k.enddate,k.actualamount,
k.discountamount,k.discountamount, c.name as category
FROM koupon.koupon k
INNER JOIN koupon.category c on c.categoryid = k.categoryid
where
k.startDate&lt; = NOW()和endDate&gt; = NOW()
AND c.isActive=true AND c.isDeleted=false AND k.isActive =true AND lower(k.status)=lower('approved')
order by k.kouponid">
<field column="kid" name="kid"/>
<field column="name" name="name"/>
<field column="image" name="image"/>
<field column="description" name="description"/>
<field column="startdate" name="startdate"/>
<field column="enddate" name="enddate"/>
<field column="actualamount" name="actualamount"/>
<field column="discountamount" name="discountamount"/>
<field column="discount" name="discount"/>
<field column="category" name="category"/>
</entity>
</document>
</dataConfig>
在此代码中,使用"k.startDate <= NOW() and endDate >= NOW()"
来提取记录但solr
查询不提供此内容。
我有一个解决方案,开始“结束”,但这不是确切的解决方案..
我对这个问题非常厌倦了解这个问题?怎么解决这个?
答案 0 :(得分:0)
您可以尝试使用此mysql查询进行索引:
WHERE (NOW() BETWEEN k.startDate and k.endDate)
而不是:
k.startDate <= NOW() and endDate >= NOW()
防止错误
属性&#34;查询&#34;的值与元素类型相关联 &#34;实体&#34;不得包含&#39;&lt;&#39;字符
对于您的Solr查询
startdate:[* to NOW]
要工作,请确保您的startdate字段符合Solr dateField类型。有关详细信息,请查看this链接