Skip to content

Commit b11b2be

Browse files
author
Jim Leether
committed
Updated higlighting result/version number
Updated version number in examples. Updated highlighting result to accept field name as an argument.
1 parent 374fca8 commit b11b2be

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

autoSuggestExample.cfm

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
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" />
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+
<html>
13+
<head>
14+
<title>CFSolrLib 3.0 | Auto-Suggest example</title>
15+
</head>
16+
<body>
17+
18+
Keyword: <input id="keyword" />
19+
20+
</body>
21+
</html>

components/cfsolrlib.cfc

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<cfargument name="q" type="string" required="true" hint="Your query string" />
5454
<cfargument name="start" type="numeric" required="false" default="0" hint="Offset for results, starting with 0" />
5555
<cfargument name="rows" type="numeric" required="false" default="20" hint="Number of rows you want returned" />
56+
<cfargument name="highlightingField" type="string" required="false" hint="Name of the field used for the highlighting result" />
5657
<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." />
5758
<cfset var thisQuery = THIS.javaLoaderInstance.create("org.apache.solr.client.solrj.SolrQuery").init(ARGUMENTS.q).setStart(ARGUMENTS.start).setRows(ARGUMENTS.rows) />
5859
<cfset var thisParam = "" />
@@ -100,10 +101,9 @@
100101
</cfif>
101102

102103
<!--- Highlighting Response --->
103-
<cfif NOT isNull(response.getHighlighting())>
104+
<cfif NOT isNull(response.getHighlighting()) AND structKeyExists(ARGUMENTS,"highlightingField")>
104105
<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") />
106+
<cfset currentResult.highlightingResult = response.getHighlighting().get("#currentResult.get('id')#").get("#ARGUMENTS.highlightingField#") />
107107
</cfloop>
108108
</cfif>
109109
<cfreturn duplicate(ret) /> <!--- duplicate clears out the case-sensitive structure --->

index.cfm

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<cfset sampleSolrInstance = createObject("component","components.cfsolrlib").init(APPLICATION.javaloader,"localhost","8983","/solr") />
22
<html>
33
<head>
4-
<title>CFSolrLib 2.0</title>
4+
<title>CFSolrLib 3.0</title>
55
</head>
66
<body>
77
<h2>Welcome to CFSolrLib</h2>
88
<p>CFSolrLib is a library that lets you interact directly with a Solr server, using the native java client library.</p>
99

1010
<h2>Requirements</h2>
1111
<p>
12-
You need a few basic things to use CFSolrLib 2:<br/>
12+
You need a few basic things to use CFSolrLib 3:<br/>
1313
<ul>
1414
<li>A Solr server, version 4.0 or greater. This was built &amp; tested with Solr 4.0. This library will not work with earlier versions of Solr.</li>
1515
<li><a href="http://wiki.apache.org/solr/Solrj">SolrJ</a> - The Solr java client library and supporting java libraries.</li>

indexExample.cfm

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ FROM art
4444

4545
<html>
4646
<head>
47-
<title>CFSolrLib 2.0 | Indexing example</title>
47+
<title>CFSolrLib 3.0 | Indexing example</title>
4848
</head>
4949
<body>
5050
<h2>Indexing</h2>

searchExample.cfm

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
<cfset local.params["hl.fragmentsBuilder"] = "colored">
1212
<cfset local.params["hl.boundaryScanner"] = "default">
1313
<cfset local.params["hl.usePhraseHighlighter"] = true>
14-
<cfset searchResponse = sampleSolrInstance.search(URL.q,0,100,local.params) />
14+
<cfset searchResponse = sampleSolrInstance.search(URL.q,0,100,local.params,,"title") />
1515
<cfelse>
1616
<cfset searchResponse = sampleSolrInstance.search(URL.q,0,100) />
1717
</cfif>
1818

1919
<cfoutput>
2020
<html>
2121
<head>
22-
<title>CFSolrLib 2.0 | Search Example</title>
22+
<title>CFSolrLib 3.0 | Search Example</title>
2323
</head>
2424
<body>
2525
<h2>Search Example</h2>

0 commit comments

Comments
 (0)