我使用ColdFusion作为我的应用程序的服务器端语言,并使用Solr作为搜索服务器。在开发过程中,我已经碰壁了!带过滤的url solr查询语法如下所示(没有换行)
http://localhost:8090/solr/areios_pagos/select?&q=*&fq=apofasi_date:(2002)&wt=json&indent=on
问题
当我直接查询solr(使用特定的过滤器)时,我得到了一个成功的输出。查询如下:
http://localhost:8090/solr/areios_pagos/select?&q=*&fq=apofasi_number:(1)&wt=json&indent=on
当我尝试在ColdFusion的帮助下构建上述查询时(参见下面的CFC),它只有一个过滤器(apofasi_number :())和“q”值asterisk(*)失败。有趣的是,它失败的值为“1”而不是“66”!我尝试了很多东西(甚至是硬编码的参数)。请记住,如果我直接查询solr,使用特定的过滤器,它可以工作!
<cfcomponent output="false">
<cfprocessingdirective pageencoding="utf-8">
<cfset setEncoding("URL", "utf-8")>
<cffunction name="searchP" access="remote" returnFormat="json">
<cfargument name="q" type="string" default="" required="no">
<cfargument name="fq" type="string" default="" required="no">
<cfset theUrl = 'http://localhost/solr/areios_pagos/select/?'>
<cfhttp method="get" url="#theUrl#" port="8090" result="rs" username="********" password="********">
<cfhttpparam type="url" name="q" value="#q#">
<cfhttpparam type="url" name="fq" value="#fq#">
<cfhttpparam type="url" name="rows" value="120">
<cfhttpparam type="url" name="wt" value="json">
<cfhttpparam type="url" name="sort" value="score desc">
<cfhttpparam type="url" name="hl" value="true">
<cfhttpparam type="url" name="hl.fl" value="content,title">
<cfhttpparam type="url" name="hl.alternateField" value="content">
<cfhttpparam type="url" name="hl.maxAlternateFieldLength" value="850">
<cfhttpparam type="url" name="hl.fragmenter" value="gap">
<cfhttpparam type="url" name="hl.maxAnalyzedChars" value="-1">
<cfhttpparam type="url" name="hl.fragsize" value="850">
</cfhttp>
<cfset theData = deserializeJson(rs.FileContent)>
<cfset check = theData.response.numFound>
<cfset forsolr = createObject("java", "java.util.LinkedHashMap").init() />
<cfset forsolr['docs'] = theData.response.docs>
<cfset docsHighlitedRaw = theData.highlighting>
<cfset i = 1>
<cfset result = ArrayNew(1)>
<cfloop collection="#docsHighlitedRaw#" item="key" >
<cfset content = createObject("java", "java.util.LinkedHashMap").init() />
<cfset content['solr_id'] = #key#>
<cfset content['content'] = #docsHighlitedRaw[key].content[1]#>
<cfset content['keywordlist'] = keyWordsExtract(#content['content']#)>
<cfset result[i] = content>
<cfset i = i + 1>
</cfloop>
<cfset forsolr1 = createObject("java", "java.util.LinkedHashMap").init() />
<cfset forsolr1['docs'] = result>
<cfset result = ArrayOfStructsMerge(forsolr.docs, forsolr1.docs, "solr_id")>
<cfif check LT 1>
<cfset output = {"docs" = result, "success" = "false"}>
<cfelse>
<cfset output = {"docs" = result, "success" = "true"}>
</cfif>
<cfreturn output>
</cffunction>
<cffunction name="ArrayOfStructsMerge" returntype="array" access="public" output="no">
<cfargument name="left" type="array" required="yes">
<cfargument name="right" type="array" required="yes">
<cfargument name="id" type="string" required="yes">
<cfset var result = Duplicate(arguments.left)>
<cfset var element = "">
<cfset var key = "">
<cfset var currentId = "">
<cfset var lookup = StructNew()>
<cfloop array="#result#" index="element">
<cfif IsStruct(element) and StructKeyExists(element, arguments.id)>
<cfset currentId = element[arguments.id]>
<cfset lookup[currentId] = element>
</cfif>
</cfloop>
<cfloop array="#arguments.right#" index="element">
<cfif IsStruct(element) and StructKeyExists(element, arguments.id)>
<cfset currentId = element[arguments.id]>
<cfif StructKeyExists(lookup, currentId)>
<cfloop collection="#element#" item="key">
<cfset lookup[currentId][key] = Duplicate(element[key])>
</cfloop>
<cfelse>
<cfset ArrayAppend(result, Duplicate(element))>
</cfif>
</cfif>
</cfloop>
<cfreturn result>
</cffunction>
<cffunction name="keyWordsExtract" access="public" output="no" returntype="string">
<cfargument name="html" required="yes" type="string">
<cfset html = #Arguments.html#>
<cfset matches = rematch("<shl>[^<]*</shl>", html)>
<cfset results = ArrayNew(1)>
<cfloop array="#matches#" index="match">
<cfset output = arrayAppend(results, rereplace(match, "<shl>(.*)</shl>", "\1") )>
</cfloop>
<cfset keyWords = ArrayToList(results, ",")>
<cfreturn keyWords>
</cffunction>
</cfcomponent>
我确信这是一个ColdFusion问题。我已经摔跤了几个星期,以了解上述代码出了什么问题。任何建议将不胜感激!
由于