Skip to content

Commit

Permalink
Updated lib to accurately implement query.setParam().
Browse files Browse the repository at this point in the history
  • Loading branch information
Shannon Hicks committed Sep 11, 2011
1 parent d2d950f commit 68dd929
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,2 +1,4 @@
/solr-server/solr/data/index/
/solr-server/solr/data/spellcheck/

.DS_Store
31 changes: 27 additions & 4 deletions components/cfsolrlib.cfc
Expand Up @@ -53,23 +53,46 @@
<cfargument name="q" type="string" required="true" hint="Your query string" />
<cfargument name="start" type="numeric" required="false" default="0" hint="Offset for results, starting with 0" />
<cfargument name="rows" type="numeric" required="false" default="20" hint="Number of rows you want returned" />
<cfargument name="params" type="array" required="false" default="#arrayNew(1)#" hint="An array of name value pairs of additional params. Values do not need to be only strings." />
<cfargument name="params" type="struct" required="false" default="#structNew#" hint="A struct of data to add as params. The struct key will be used as the param name, and the value as the param's value. If you need to pass in multiple values, make the value an array of values." />
<cfset var thisQuery = THIS.javaLoaderInstance.create("org.apache.solr.client.solrj.SolrQuery").init(ARGUMENTS.q).setStart(ARGUMENTS.start).setRows(ARGUMENTS.rows) />
<cfset var thisParam = "" />
<cfset var response = "" />
<cfset var ret = structNew() />
<cfloop array="#ARGUMENTS.params#" index="thisParam">
<cfset thisQuery.setParam(thisParam.name,thisParam.value)>

<cfloop list="#structKeyList(ARGUMENTS.params)#" index="thisKey">
<cfif isArray(ARGUMENTS.params[thisKey])>
<cfset thisQuery.setParam(thisKey,javaCast("string[]",ARGUMENTS.params[thisKey])) />
<cfelseif isBoolean(ARGUMENTS.params[thisKey])>
<cfset thisQuery.setParam(thisKey,ARGUMENTS.params[thisKey]) />
<cfelse>
<cfset tempArray = arrayNew(1) />
<cfset arrayAppend(tempArray,ARGUMENTS.params[thisKey]) />
<cfset thisQuery.setParam(thisKey,javaCast("string[]",tempArray)) />
</cfif>
</cfloop>

<!--- we do this instead of making the user call java functions, to work around a CF bug --->
<cfset response = THIS.solrQueryServer.query(thisQuery) />
<cfset ret.results = response.getResults() / >
<cfset ret.spellCheck = response.getSpellCheckResponse() / >
<cfset ret.spellCheck = response.getSpellCheckResponse() />

<cfreturn duplicate(ret) /> <!--- duplicate clears out the case-sensitive structure --->
</cffunction>

<cffunction name="queryParam" access="public" output="false" returnType="array" hint="Creates a name/value pair and appends it to the array. This is a helper method for adding to your index.">
<cfargument name="paramArray" required="true" type="array" hint="An array to add your document field to." />
<cfargument name="name" required="true" type="string" hint="Name of your field." />
<cfargument name="value" required="true" type="any" hint="Value of your field." />

<cfset var thisField = structNew() />
<cfset thisField.name = ARGUMENTS.name />
<cfset thisField.value = ARGUMENTS.value />

<cfset arrayAppend(ARGUMENTS.paramArray,thisField) />

<cfreturn ARGUMENTS.paramArray />
</cffunction>

<cffunction name="add" access="public" output="false" hint="Add a document to the Solr index">
<cfargument name="doc" type="array" required="true" hint="An array of field objects, with name, value, and an optional boost attribute. {name:""Some Name"",value:""Some Value""[,boost:5]}" />
<cfargument name="docBoost" type="numeric" required="false" hint="Value of boost for this document." />
Expand Down
4 changes: 2 additions & 2 deletions indexExample.cfm
Expand Up @@ -19,8 +19,8 @@ FROM art
// example for indexing content from a rich file
myFile = expandPath("NRRcreditsbyartist.pdf");
fmap = structNew();
fmap.title = "title";
fmap.content = "text";
fmap["title"] = "title";
fmap["content"] = "text";
sampleSolrInstance.addFile("file-1",myFile,fmap,true,"attr_");
sampleSolrInstance.commit(); // do a final commit of our changes
Expand Down
Binary file removed solr-server/.DS_Store
Binary file not shown.
Binary file removed solr-server/solr/.DS_Store
Binary file not shown.

0 comments on commit 68dd929

Please sign in to comment.