-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindexExample.cfm
59 lines (49 loc) · 2.18 KB
/
indexExample.cfm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<cfset sampleSolrInstance = createObject("component","components.cfsolrlib").init(APPLICATION.javaloader,"localhost","8983","/solr") />
<cfquery name="getArt" datasource="cfartgallery">
SELECT artID, artname, description, firstName, lastName, isSold
FROM art
LEFT JOIN artists
ON art.artistId = artists.artistId
</cfquery>
<cfscript>
// example for indexing content from a database
for (i=1;i LTE getArt.recordcount;i=i+1) {
thisDoc = arrayNew(1);
thisDoc = sampleSolrInstance.addField(thisDoc,"id",getArt.artID[i]);
thisDoc = sampleSolrInstance.addField(thisDoc,"title",getArt.artname[i]);
thisDoc = sampleSolrInstance.addField(thisDoc,"cat",trim(getArt.description[i]));
thisFullname = trim(getArt.firstName[i]&" "&getArt.lastName[i]);
thisDoc = sampleSolrInstance.addField(thisDoc,"author",thisFullname);
thisDoc = sampleSolrInstance.addField(thisDoc,"availability_s",iif(getArt.isSold[i] EQ 1,DE("Sold"),DE("Available")));
sampleSolrInstance.add(thisDoc);
}
// example for indexing content from a rich file
myFile = expandPath("NRRcreditsbyartist.pdf");
// To Parse File Content with Tika on the ColdFusion Side
local.fileObject = application.tika.parseToString(createObject("java","java.io.File").init(myfile));
thisFile = arrayNew(1);
thisFile = sampleSolrInstance.addField(thisFile,"text",local.fileObject);
thisFile = sampleSolrInstance.addField(thisFile,"id","file-1");
thisFile = sampleSolrInstance.addField(thisFile,"title","File Title");
sampleSolrInstance.add(thisFile);
// To Stream File to Solr
fmap = structNew();
fmap["title"] = "title";
fmap["content"] = "text";
sampleSolrInstance.addFile("file-2",myFile,fmap,true,"attr_");
sampleSolrInstance.commit(); // do a final commit of our changes
sampleSolrInstance.optimize(); // since we're all done, optimize the index
h = new http();
h.setMethod("get");
h.setURL("http://localhost:8983/solr/suggest?spellcheck.build=true");
h.send();
</cfscript>
<html>
<head>
<title>CFSolrLib 3.0 | Indexing example</title>
</head>
<body>
<h2>Indexing</h2>
<p>Done. There's nothing to output, you'll want to look at the CF source.</p>
</body>
</html>