简体   繁体   English

cfindex之后,ColdFusion 10 Solr cfsearch有时仅返回结果

[英]ColdFusion 10 Solr cfsearch after cfindex returning results only sometimes

This is my first foray into using cfsearch. 这是我第一次使用cfsearch。 I have the below code working on my dev server with ColdFusion 10, and a collection I previously created. 我将以下代码与ColdFusion 10一起在我的开发服务器上工作,并使用我先前创建的集合。

The only way I can get this to return consistent results is to place a "sleep" between the cfindex and cfsearch. 我可以获得此结果以返回一致结果的唯一方法是在cfindex和cfsearch之间放置一个“睡眠”。 Otherwise the search returns no results 90% of the time and on occasion some or all results. 否则,搜索将在90%的时间内不返回任何结果,有时还会返回部分或全部结果。 My query only has 3 records and the collection has been optimized. 我的查询只有3条记录,并且已对集合进行了优化。

It is important to refresh the collection as this is a business directory that will be changing frequently. 刷新集合非常重要,因为这是一个经常更改的业务目录。

<form action="search.cfm" method="get">
<input type="text" name="searchFor">
<input type="submit" value="Search">
</form>

<cfquery name="qryData" datasource="#session.DataSource#">
    SELECT biz_id, biz_name, biz_city, biz_state, biz_county
    FROM biz
   WHERE user_level > 0 AND user_level < 99
</cfquery>
<cfindex collection="mySearch" action="refresh" body="biz_name,biz_city,biz_state,biz_county" key="biz_id" query="qryData">

<cfset sleep(100)>

<cfsearch name="search" collection="mySearch" criteria="#url.searchFor#" maxrows="100">
<cfdump var="#search#">

The Solr server will need a moment of time to commit the changes you've made to the index. Solr服务器将需要一些时间来提交对索引所做的更改。

In general it's a very bad idea to do the <cfindex> and the <cfsearch> in the same request, even more so if you do it for every search request that's being made. 通常,在同一个请求中执行<cfindex><cfsearch>是一个非常糟糕的主意,如果您对发出的每个搜索请求都这样做,则更是如此。

If you need frequent updates to the index, create a scheduled task that runs every so often and keeps the index up to date: 如果您需要经常更新索引,请创建一个定期运行的计划任务,并使其保持最新状态:

<cfquery name="qryData" datasource="#session.DataSource#">
    SELECT biz_id, biz_name, biz_city, biz_state, biz_county
    FROM biz
   WHERE user_level > 0 AND user_level < 99
</cfquery>

<cfindex 
   collection="mySearch" 
   action="refresh" 
   query="qryData"
   key="biz_id" 
   body="biz_name,biz_city,biz_state,biz_county" 
>

And then run your search separately. 然后分别运行搜索。

<form action="search.cfm" method="get">
  <input type="text" name="searchFor">
  <input type="submit" value="Search">
</form>

<cfsearch name="search" collection="mySearch" criteria="#url.searchFor#" maxrows="100">
<cfdump var="#search#">

Note that ColdFusion 10 supports the deltaimport action which might be more efficient than doing a full refresh. 请注意,ColdFusion 10支持deltaimport操作该操作可能比执行完整刷新更有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM