Skip to content

Commit 4cdb92d

Browse files
author
Jim Leether
committed
Updates to CFSolrLib for Solr 4.0.0. Updated jar files for SolrJ, updated version of JavaLoader, included JQueryUI for JQuery AutoComplete and included Solr 4.0.0.
1 parent 3d2a655 commit 4cdb92d

File tree

712 files changed

+89581
-26354
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

712 files changed

+89581
-26354
lines changed

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/solr-server/solr/data/index/
2-
/solr-server/solr/data/spellcheck/
1+
/solr-server/solr/collection1/data/index/
2+
/solr-server/solr/collection1/data/spellcheck/
3+
/solr-server/solr/collection1/data/autosuggest/
34

45
.DS_Store

Application.cfc

+23-11
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,30 @@
44
<cfscript>
55
// load libraries needed for solrj
66
var paths = arrayNew(1);
7-
arrayAppend(paths,expandPath("solrj-lib/commons-io-1.4.jar"));
8-
arrayAppend(paths,expandPath("solrj-lib/commons-codec-1.4.jar"));
9-
arrayAppend(paths,expandPath("solrj-lib/slf4j-api-1.5.5.jar"));
10-
arrayAppend(paths,expandPath("solrj-lib/slf4j-jdk14-1.5.5.jar"));
11-
arrayAppend(paths,expandPath("solrj-lib/commons-httpclient-3.1.jar"));
12-
arrayAppend(paths,expandPath("solrj-lib/apache-solr-solrj-3.2.0.jar"));
13-
arrayAppend(paths,expandPath("solrj-lib/geronimo-stax-api_1.0_spec-1.0.1.jar"));
14-
arrayAppend(paths,expandPath("solrj-lib/wstx-asl-3.2.7.jar"));
15-
arrayAppend(paths,expandPath("solrj-lib/jcl-over-slf4j-1.5.5.jar"));
7+
arrayAppend(paths,expandPath("solrj-lib/solr-solrj-4.0.0-BETA.jar"));
8+
arrayAppend(paths,expandPath("solrj-lib/commons-io-2.4.jar"));
9+
arrayAppend(paths,expandPath("solrj-lib/commons-codec-1.7.jar"));
10+
arrayAppend(paths,expandPath("solrj-lib/slf4j-api-1.6.6.jar"));
11+
arrayAppend(paths,expandPath("solrj-lib/slf4j-jdk14-1.6.6.jar"));
12+
arrayAppend(paths,expandPath("solrj-lib/jcl-over-slf4j-1.6.6.jar"));
13+
arrayAppend(paths,expandPath("solrj-lib/log4j-over-slf4j-1.6.6.jar"));
14+
arrayAppend(paths,expandPath("solrj-lib/httpclient-4.2.1.jar"));
15+
arrayAppend(paths,expandPath("solrj-lib/httpcore-4.2.2.jar"));
16+
arrayAppend(paths,expandPath("solrj-lib/httpmime-4.2.1.jar"));
17+
arrayAppend(paths,expandPath("solrj-lib/stax-api-1.0.1.jar"));
18+
arrayAppend(paths,expandPath("solrj-lib/wstx-asl-4.0.0.jar"));
19+
arrayAppend(paths,expandPath("solrj-lib/tika-app-1.2.jar"));
1620

1721
// create an application instance of JavaLoader
18-
APPLICATION.javaloader = createObject("component", "javaloader.JavaLoader").init(paths);
19-
22+
APPLICATION.javaloader = createObject("component", "javaloader.JavaLoader").init(loadpaths=paths, loadColdFusionClassPath=true);
23+
// setup tika
24+
APPLICATION.tika = APPLICATION.javaloader.create("org.apache.tika.Tika").init();
25+
2026
</cfscript>
2127
</cffunction>
28+
29+
<cffunction name="onRequestStart">
30+
<cfif structKeyExists(url, "reinit")>
31+
<cfset onApplicationStart()>
32+
</cfif>
33+
</cffunction>

autoSuggestExample.cfm

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script src="js/jquery-1.7.2.js"></script>
2+
<script src="js/jqueryui/jqueryui-1.8.22.js"></script>
3+
<link rel="stylesheet" href="css/jqueryui/jqueryui-1.8.22.css" type="text/css" />
4+
<script type="text/javascript">
5+
$(function() {
6+
$("#keyword").autocomplete({
7+
source: "components/cfsolrlib.cfc?method=getAutoSuggestResults&returnformat=json"
8+
});
9+
});
10+
</script>
11+
12+
Keyword: <input id="keyword" />

components/cfsolrlib.cfc

+59-7
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333

3434
<cfscript>
3535
// create an update server instance
36-
THIS.solrUpdateServer = THIS.javaLoaderInstance.create("org.apache.solr.client.solrj.impl.StreamingUpdateSolrServer").init(THIS.solrURL,THIS.queueSize,THIS.threadCount);
36+
THIS.solrUpdateServer = THIS.javaLoaderInstance.create("org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrServer").init(THIS.solrURL,THIS.queueSize,THIS.threadCount);
3737

3838
// create a query server instance
39-
THIS.solrQueryServer = THIS.javaLoaderInstance.create("org.apache.solr.client.solrj.impl.CommonsHttpSolrServer").init(THIS.solrURL);
39+
THIS.solrQueryServer = THIS.javaLoaderInstance.create("org.apache.solr.client.solrj.impl.HttpSolrServer").init(THIS.solrURL);
4040

4141
// enable binary
4242
if (ARGUMENTS.binaryEnabled) {
@@ -78,8 +78,10 @@
7878

7979
<!--- we do this instead of making the user call java functions, to work around a CF bug --->
8080
<cfset response = THIS.solrQueryServer.query(thisQuery) />
81-
<cfset ret.results = response.getResults() / >
81+
<cfset ret.results = response.getResults() / >
8282
<cfset ret.totalResults = response.getResults().getNumFound() / >
83+
84+
<!--- Spellchecker Response --->
8385
<cfif NOT isNull(response.getSpellCheckResponse())>
8486
<cfset suggestions = response.getSpellCheckResponse().getSuggestions() />
8587
<cfset ret.collatedSuggestion = response.getSpellCheckResponse().getCollatedResult() />
@@ -96,8 +98,58 @@
9698
<cfset arrayAppend(ret.spellCheck,thisSuggestion) />
9799
</cfloop>
98100
</cfif>
99-
100-
<cfreturn duplicate(ret) /> <!--- duplicate clears out the case-sensitive structure --->
101+
102+
<!--- Highlighting Response --->
103+
<cfif NOT isNull(response.getHighlighting())>
104+
<cfloop array="#ret.results#" index="currentResult">
105+
<!--- ***"title" is used for the highlighting example. Change "title" to the field your highlighting result will be in for your use.--->
106+
<cfset currentResult.highlightingResult = response.getHighlighting().get("#currentResult.get('id')#").get("title") />
107+
</cfloop>
108+
</cfif>
109+
<cfreturn duplicate(ret) /> <!--- duplicate clears out the case-sensitive structure --->
110+
</cffunction>
111+
112+
<cffunction name="getAutoSuggestResults" access="remote" returntype="any" output="false">
113+
<cfargument name="term" type="string" required="no">
114+
<cfif Len(trim(ARGUMENTS.term)) gt 0>
115+
<!--- Remove any leading spaces in the search term --->
116+
<cfset ARGUMENTS.term = "#trim(ARGUMENTS.term)#">
117+
<cfscript>
118+
h = new http();
119+
h.setMethod("get");
120+
h.setURL("#THIS.solrURL#/suggest?q=#ARGUMENTS.term#");
121+
local.suggestResponse = h.send().getPrefix().Filecontent;
122+
if (isXML(local.suggestResponse)){
123+
local.XMLResponse = XMLParse(local.suggestResponse);
124+
local.wordList = "";
125+
if (ArrayLen(XMLResponse.response.lst) gt 1 AND structKeyExists(XMLResponse.response.lst[2].lst, "lst")){
126+
local.wordCount = ArrayLen(XMLResponse.response.lst[2].lst.lst);
127+
For (j=1;j LTE local.wordCount; j=j+1){
128+
if(j eq local.wordCount){
129+
local.resultCount = XMLResponse.response.lst[2].lst.lst[j].int[1].XmlText;
130+
local.resultList = arrayNew(1);
131+
For (i=1;i LTE local.resultCount; i=i+1){
132+
arrayAppend(local.resultList, local.wordList & XMLResponse.response.lst[2].lst.lst[j].arr.str[i].XmlText);
133+
}
134+
}else{
135+
local.wordList = local.wordList & XMLResponse.response.lst[2].lst.lst[j].XMLAttributes.name & " ";
136+
}
137+
}
138+
//sort results aphabetically
139+
if (ArrayLen(local.resultList)){
140+
ArraySort(local.resultList,"textnocase","asc");
141+
}
142+
}else{
143+
local.resultList = "";
144+
}
145+
}else{
146+
local.resultList = "";
147+
}
148+
</cfscript>
149+
<cfelse>
150+
<cfset local.resultList = "">
151+
</cfif>
152+
<cfreturn local.resultList />
101153
</cffunction>
102154

103155
<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.">
@@ -163,8 +215,8 @@
163215
<cfargument name="boost" required="false" type="struct" hint="A struct of boost values. The struct key will be the field name to boost, and its value is the numeric boost value" />
164216
<cfargument name="idFieldName" required="false" type="string" default="id" hint="The name of the unique id field in the Solr schema" />
165217
<cfset var docRequest = THIS.javaLoaderInstance.create("org.apache.solr.client.solrj.request.ContentStreamUpdateRequest").init("/update/extract") />
166-
<cfset var thisKey = "" />
167-
<cfset docRequest.addFile(createObject("java","java.io.File").init(ARGUMENTS.file)) />
218+
<cfset var thisKey = "" />
219+
<cfset docRequest.addFile(createObject("java","java.io.File").init(ARGUMENTS.file),"application/octet-stream") />
168220
<cfset docRequest.setParam("literal.#arguments.idFieldName#",ARGUMENTS.id) />
169221
<cfif ARGUMENTS.saveMetadata>
170222
<cfset docRequest.setParam("uprefix",metadataPrefix) />
180 Bytes
Loading
178 Bytes
Loading
120 Bytes
Loading
Loading
Loading
Loading
Loading
4.27 KB
Loading
4.27 KB
Loading
4.27 KB
Loading
4.27 KB
Loading
4.27 KB
Loading

0 commit comments

Comments
 (0)