-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSearcher.cfc
681 lines (578 loc) · 24.6 KB
/
Searcher.cfc
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
<!--- 1.0 RC (Build 9) --->
<!--- Last Updated: 2012-01-24 --->
<!--- Created by Steve Bryant 2005-10-20 --->
<!--- Information: sebtools.com --->
<!---
Desired Features:
Create collections to be searched
Index and repair collections
Run a search and return results
Keep track of searches
Provide Google-like ability to suggest spelling corrections
Optionally run search through google
--->
<cfcomponent displayname="Searcher" hint="I manage search functionality. I will usually be extended by a site-specific search object.">
<cffunction name="init" access="public" returntype="any" output="no" hint="I initialize and return this object.">
<cfargument name="CollectionPath" type="string" required="yes">
<cfargument name="DataMgr" type="any" required="yes">
<cfargument name="sendpage" type="string" default="">
<cfargument name="excludedirs" type="string" default="">
<cfargument name="excludefiles" type="string" default="">
<cfargument name="UseGoogleSyntax" type="boolean" default="false">
<cfargument name="Deployer" type="any" required="false">
<cfreturn initInternal(argumentCollection=arguments)>
</cffunction>
<cffunction name="initInternal" access="private" returntype="any" output="no" hint="I initialize and return this object.">
<cfargument name="CollectionPath" type="string" required="yes">
<cfargument name="DataMgr" type="any" required="yes">
<cfargument name="sendpage" type="string" default="">
<cfargument name="excludedirs" type="string" default="">
<cfargument name="excludefiles" type="string" default="">
<cfargument name="UseGoogleSyntax" type="boolean" default="false">
<cfargument name="Deployer" type="any" required="false">
<cfset var qTest = 0>
<cfscript>
variables.path = arguments.CollectionPath;
variables.DataMgr = arguments.DataMgr;
variables.datasource = variables.DataMgr.getDatasource();
variables.DataMgr.loadXML(getDbXml(),true);
variables.Collections = "";
variables.sendpage = arguments.sendpage;
variables.excludedirs = arguments.excludedirs;
variables.excludefiles = arguments.excludefiles;
variables.UseGoogleSyntax = arguments.UseGoogleSyntax;
if ( StructKeyExists(arguments,"Deployer") ) {
variables.Deployer = arguments.Deployer;
}
</cfscript>
<cfreturn this>
</cffunction>
<cffunction name="addCollection" access="public" returntype="void" output="no">
<cfargument name="CollectionName" type="string" required="yes">
<!--- If this collection isn't already known to Searcher, add it. --->
<cfif NOT ListFindNoCase(variables.Collections, CollectionName)>
<cfset variables.Collections = ListAppend(variables.Collections, CollectionName)>
</cfif>
</cffunction>
<cffunction name="create" access="public" returntype="void" output="no" hint="I create the given collection.">
<cfargument name="CollectionName" type="string" required="yes">
<cfargument name="recreate" type="boolean" default="false">
<cfif StructKeyExists(variables,"Deployer") AND NOT Arguments.recreate>
<cfset Variables.Deployer.deploy(
Name="Searcher:create:#Arguments.CollectionName#",
ComponentPath="com.sebtools.Searcher",
Component=This,
MethodName="create_Actual",
Args=Arguments
)>
<cfelse>
<cfset create_Actual(ArgumentCollection=Arguments)>
</cfif>
</cffunction>
<cffunction name="create_Actual" access="public" returntype="void" output="no" hint="I create the given collection.">
<cfargument name="CollectionName" type="string" required="yes">
<cfargument name="recreate" type="boolean" default="false">
<cfset var qCollections = 0>
<cfset var isExisting = false>
<cflock timeout="120" throwontimeout="No" name="Searcher_CheckCollection_#arguments.CollectionName#" type="EXCLUSIVE">
<cfcollection action="LIST" name="qCollections">
<!--- <cfdump var="#qCollections#"><cfabort> --->
<cfif ListFindNoCase(ValueList(qCollections.name),arguments.CollectionName)>
<!--- <cfquery name="qCollections" dbtype="query">
SELECT *
FROM qCollections
WHERE Name = '#arguments.CollectionName#'
</cfquery>
<cfif qCollections.RecordCount>
<cfif ListFindNoCase(qCollections.ColumnList,"External") AND qCollections.External IS "NOT FOUND">
<cflock timeout="20" throwontimeout="No" name="Searcher_DeleteCollection" type="EXCLUSIVE">
<cfcollection action="DELETE" collection="#arguments.CollectionName#">
</cflock>
<cfelse>
<cfset isExisting = true>
</cfif>
</cfif> --->
<cfset isExisting = true>
</cfif>
<!--- arguments.recreate OR NOT --->
<cfif NOT isExisting>
<cftry>
<cflock timeout="40" throwontimeout="No" name="Searcher_CreateCollection_#arguments.CollectionName#" type="EXCLUSIVE">
<cfcollection action="CREATE" collection="#arguments.CollectionName#" path="#variables.path#" language="English">
</cflock>
<cfcatch>
<!---<cfif
ListFindNoCase(ValueList(qCollections.name),arguments.CollectionName)
OR CFCATCH.Detail CONTAINS "has already been registered"
OR CFCATCH.Detail CONTAINS "Unable to create collection"
>--->
<cfset deleteDirectory("#variables.path##getDirDelim()##LCase(arguments.CollectionName)#")>
<cfcollection action="LIST" name="qCollections">
<cfloop query="qCollections">
<cfif name EQ CollectionName>
<cflock timeout="40" throwontimeout="Yes" name="Searcher_DeleteCollection_#arguments.CollectionName#" type="EXCLUSIVE">
<cfset deleteDirectory(path)>
<cfcollection action="DELETE" collection="#name#">
</cflock>
</cfif>
</cfloop>
<cflock timeout="40" throwontimeout="No" name="Searcher_CreateCollection_#arguments.CollectionName#" type="EXCLUSIVE">
<cfcollection action="CREATE" collection="#arguments.CollectionName#" path="#variables.path#" language="English">
</cflock>
<!---<cfelse>
<cfrethrow>
</cfif>--->
</cfcatch>
</cftry>
</cfif>
</cflock>
<!--- <cfif arguments.recreate>
<cftry>
<cfcollection action="CREATE" collection="#arguments.CollectionName#" path="#variables.path#" language="English">
<cfcatch>
</cfcatch>
</cftry>
<cfelse>
<cfcollection action="LIST" name="qCollections">
<cfif NOT ListFindNoCase(ValueList(qCollections.name),arguments.CollectionName)>
<cfcollection action="CREATE" collection="#arguments.CollectionName#" path="#variables.path#" language="English">
</cfif>
</cfif> --->
<!--- <cftry>
<cfcollection action="CREATE" collection="#arguments.CollectionName#" path="#variables.path#" language="English">
<cfcatch>
<cfif NOT CFCATCH.Detail CONTAINS "has already been registered">
<cfrethrow>
</cfif>
</cfcatch>
</cftry> --->
<!--- If this collection isn't already known to Searcher, add it. --->
<cfset addCollection(arguments.CollectionName)>
</cffunction>
<cffunction name="getCollections" access="public" returntype="string" output="no" hint="I return a list of all of the collections used by Searcher.">
<cfreturn variables.Collections>
</cffunction>
<cffunction name="index" access="public" returntype="boolean" output="no" hint="I index the collection(s) to be searched.">
<cfabort showerror="This Method is Abstract and needs to be overridden">
</cffunction>
<cffunction name="indexPath" access="public" returntype="void" output="no" hint="I index a path collection and add it to the Searcher.">
<cfargument name="CollectionName" type="string" required="yes">
<cfargument name="Key" type="string" required="yes">
<cfargument name="extensions" type="string" default="htm,html,cfm,cfml,dbm,dbml">
<!--- Try to index the given collection name from the given path --->
<cflock timeout="120" throwontimeout="yes" name="Searcher_IndexQuery_#arguments.CollectionName#" type="EXCLUSIVE">
<cftry>
<cfindex action="REFRESH" collection="#arguments.CollectionName#" key="#arguments.Key#" type="PATH" recurse="Yes" extensions="#Arguments.extensions#">
<cfcatch>
<!--- If index fails, try to create it and index again (exception will bubble up if it fails again) --->
<!--- <cftry> --->
<cfset create(arguments.CollectionName)>
<!--- <cfcatch> ---><!--- Try catch so that any exception return will be about cfindex, not cfcollection --->
<!--- </cfcatch>
</cftry> --->
<!--- <cfset indexPath(arguments.CollectionName,arguments.Key)> --->
<cfindex action="REFRESH" collection="#arguments.CollectionName#" key="#arguments.Key#" type="PATH" recurse="Yes" extensions="#Arguments.extensions#">
</cfcatch>
</cftry>
</cflock>
<!--- If this collection isn't already known to Searcher, add it. --->
<cfset addCollection(arguments.CollectionName)>
</cffunction>
<cffunction name="indexQuery" access="public" returntype="void" output="no" hint="I index a query collection and add it to the Searcher.">
<cfargument name="CollectionName" type="string" required="yes">
<cfargument name="query" type="query" required="yes">
<cfargument name="Key" type="string" required="yes">
<cfargument name="Title" type="string" required="yes">
<cfargument name="Body" type="string" required="yes">
<cfargument name="URLPath" type="string" default="">
<cfargument name="Custom1" type="string" default="">
<cfargument name="Custom2" type="string" default="">
<!--- Try to index the given collection name from the given path --->
<cftry>
<cflock timeout="120" throwontimeout="yes" name="Searcher_IndexQuery_#arguments.CollectionName#" type="EXCLUSIVE">
<cfindex action="REFRESH"
collection="#CollectionName#"
key="#Key#"
type="CUSTOM"
title="#Title#"
query="arguments.query"
body="#Body#"
urlpath="#URLPath#"
custom1="#Custom1#"
custom2="#Custom2#"
>
</cflock>
<cfcatch>
<cftry>
<cfset create(arguments.CollectionName,true)>
<cfcatch><!--- Try catch so that any exception return will be about cfindex, not cfcollection --->
</cfcatch>
</cftry>
<cfindex action="REFRESH"
collection="#CollectionName#"
key="#Key#"
type="CUSTOM"
title="#Title#"
query="arguments.query"
body="#Body#"
urlpath="#URLPath#"
custom1="#Custom1#"
custom2="#Custom2#"
>
</cfcatch>
</cftry>
<!--- If this collection isn't already known to Searcher, add it. --->
<cfset addCollection(arguments.CollectionName)>
</cffunction>
<cffunction name="reRun" access="public" returntype="query" output="no" hint="I return results from a search that has already been run (useful for multi-page search results).">
<cfargument name="searchid" type="numeric" required="yes">
<cfset var qSearchRecord = variables.DataMgr.getRecord('srchSearches',arguments)>
<cfset var Collections = qSearchRecord.Collections>
<cfreturn runSearch(qSearchRecord.Phrase,arguments.searchid,Collections)>
</cffunction>
<cffunction name="run" access="public" returntype="query" output="no" hint="I run a search on the given search term.">
<cfargument name="searchterm" type="string" required="yes">
<cfargument name="collections" type="string" default="#variables.Collections#" hint="A list of collections to search">
<cfset var searchid = saveSearch(arguments.searchterm,now(),arguments.collections)>
<cfset var qSearch = runSearch(arguments.searchterm,searchid,arguments.collections)>
<cfset updateSearchRecords(searchid,qSearch.RecordCount)>
<cfreturn qSearch>
</cffunction>
<cffunction name="deleteDirectory" access="private" returntype="void" output="no">
<cfargument name="path" type="string" required="yes">
<cfset var qDirectories = 0>
<cfset var dirdelim = CreateObject("java", "java.io.File").separator>
<cfset var item = "">
<cfdirectory action="LIST" directory="#arguments.path#" name="qDirectories">
<cfloop query="qDirectories">
<cfset item = ListAppend(path,Name,dirdelim)>
<cfif type eq "Dir">
<cfset deleteDirectory(item)>
<cfelse>
<cffile action="DELETE" file="#item#">
</cfif>
</cfloop>
<cfdirectory action="DELETE" directory="#path#">
</cffunction>
<cffunction name="correctURL" access="private" returntype="string" output="no">
<cfargument name="ResultURL" type="string" required="yes">
<cfargument name="Key" type="string" required="yes">
<cfset var CorrectedURL = Arguments.ResultURL>
<!--- If relative URL, start from site root --->
<cfif Len(Arguments.ResultURL) AND NOT Arguments.ResultURL CONTAINS "dummy.txt">
<cfif FileExists(Arguments.Key)>
<cfset CorrectedURL = GetFileFromPath(Arguments.Key)>
<cfelseif Left(Arguments.ResultURL,1) neq "/" AND Left(Arguments.ResultURL,7) neq "http://">
<cfset CorrectedURL = "/#Arguments.ResultURL#">
</cfif>
<cfelse>
<cfif FileExists(Arguments.Key)>
<cfset CorrectedURL = GetFileFromPath(Arguments.Key)>
<cfelse>
<cfset CorrectedURL = "/#Arguments.Key#">
</cfif>
</cfif>
<cfreturn CorrectedURL>
</cffunction>
<cffunction name="runSearch" access="private" returntype="query" output="no">
<cfargument name="searchterm" type="string" required="yes">
<cfargument name="searchid" type="numeric" required="yes">
<cfargument name="collections" type="string" default="#variables.Collections#" hint="A list of collections to search">
<cfset var qSearch = QueryNew('run')>
<cfset var liDeleteRows = "">
<cfset var thisDir = "">
<cfset var thisFile = "">
<cfset var specialchars = "()<>@">
<cfset var i = 0>
<cfset var char = "">
<cfset var aSearchID = ArrayNew(1)>
<cfif NOT Len(arguments.collections)>
<cfset arguments.collections = variables.Collections>
</cfif>
<cfif NOT Len(arguments.collections)>
<cfthrow message="Searcher does not have any collections to search." type="Searcher">
</cfif>
<cfif NOT Len(Trim(arguments.searchterm))>
<cfreturn qSearch>
</cfif>
<!--- Fix uneven quotes for potential error --->
<cfset arguments.searchterm = fixQuotes(arguments.searchterm)>
<!--- Change format from Google-like format to Verity format if UseGoogleSyntax is true --->
<cfif variables.UseGoogleSyntax>
<cfset arguments.searchterm = deGooglize(arguments.searchterm)>
</cfif>
<cfset arguments.searchterm = Trim(arguments.searchterm)>
<cfif Right(arguments.searchterm,1) EQ "\">
<cfset arguments.searchterm = Left(arguments.searchterm,Len(arguments.searchterm)-1)>
</cfif>
<cfif NOT Len(Trim(arguments.searchterm))>
<cfreturn qSearch>
</cfif>
<cftry>
<cfsearch collection="#arguments.collections#" name="qSearch" criteria="#arguments.searchterm#">
<cfcatch>
<cfif CFCATCH.Message CONTAINS "Invalid search CRITERIA specified">
<cfloop index="i" from="1" to="#Len(specialchars)#" step="1">
<cfset char = Mid(specialchars,i,1)>
<cfset arguments.searchterm = ReplaceNoCase(arguments.searchterm, char, "\#char#", "ALL")>
</cfloop>
<cfsearch collection="#arguments.collections#" name="qSearch" criteria="#arguments.searchterm#">
<cfelse>
<cfrethrow>
</cfif>
</cfcatch>
</cftry>
<cfloop query="qSearch">
<cfset QuerySetCell(qSearch,"URL",correctURL(URL,key),CurrentRow)>
<!--- Escape any ampersands in URL --->
<cfset QuerySetCell(qSearch,"URL",ReplaceNoCase(URL,"&","%26","ALL"),CurrentRow)>
<cfset QuerySetCell(qSearch,"URL",ReplaceNoCase(URL,"[Key]",KEY,"ALL"),CurrentRow)>
<!--- If any directories should be excluded from the results --->
<cfif Len(variables.excludedirs)>
<cfloop index="thisDir" list="#variables.excludedirs#">
<cfif Left(thisDir,1) neq "/"><cfset thisDir = "/#thisDir#"></cfif>
<cfif Right(thisDir,1) neq "/"><cfset thisDir = "#thisDir#/"></cfif>
<cfif URL CONTAINS thisDir>
<cfset liDeleteRows = ListAppend(liDeleteRows,CurrentRow)>
<cfbreak>
</cfif>
</cfloop>
</cfif>
<!--- If any files should be excluded from the results --->
<cfif Len(variables.excludefiles)>
<cfloop index="thisFile" list="#variables.excludefiles#">
<cfif URL eq thisFile>
<cfset liDeleteRows = ListAppend(liDeleteRows,CurrentRow)>
<cfbreak>
</cfif>
</cfloop>
</cfif>
<!--- Remove any files that have a meta tag specifying no indexing by robots --->
<cfif NOT ListFindNoCase(liDeleteRows, CurrentRow) AND FindNoCase("<meta name=#chr(34)#robots#chr(34)# content=#chr(34)#noindex", Summary)>
<cfset liDeleteRows = ListAppend(liDeleteRows,CurrentRow)>
</cfif>
<!--- Send to this component for tracking and redirection --->
<cfif Len(Trim(variables.sendpage))>
<cfset QuerySetCell(qSearch,"URL","#variables.sendpage#?searchid=#arguments.searchid#&to=#URL#",CurrentRow)>
</cfif>
<!--- If not Title, set title to file name --->
<cfif NOT Len(Title)>
<cfset QuerySetCell(qSearch,"Title",ListLast(URL,"/"),CurrentRow)>
</cfif>
</cfloop>
<cfset qSearch = QueryDeleteRows(qSearch,liDeleteRows)>
<cfloop query="qSearch">
<cfset ArrayAppend(aSearchID,arguments.searchid)>
</cfloop>
<cfset QueryAddColumn(qSearch,"SearchID",aSearchID)>
<cfreturn qSearch>
</cffunction>
<cffunction name="saveSearch" access="private" returntype="numeric" output="no" hint="I save a search and return the searchid of the saved search.">
<cfargument name="Phrase" type="string" required="yes">
<cfargument name="WhenRequested" type="date" required="yes">
<cfargument name="collections" type="string" default="#variables.Collections#" hint="A list of collections to search">
<cfreturn variables.DataMgr.insertRecord('srchSearches',arguments)>
</cffunction>
<cffunction name="updateSearchRecords" access="private" returntype="void" output="no">
<cfargument name="SearchID" type="numeric" required="yes">
<cfargument name="RecordsReturned" type="numeric" required="yes">
<cfset variables.DataMgr.updateRecord('srchSearches',arguments)>
</cffunction>
<cffunction name="send" access="remote" returntype="any" output="yes" hint="I track a search selection and the redirect the user to the desired page.">
<cfargument name="searchid" type="numeric" required="yes">
<cfargument name="to" type="string" required="yes">
<cfscript>
var stcMain = StructNew();
var stcChosen = StructNew();
stcMain.SearchID = arguments.searchid;
stcMain.LastPageChosen = arguments.to;
stcChosen.SearchID = arguments.searchid;
stcChosen.PageChosen = arguments.to;
stcChosen.WhenChosen = now();
variables.DataMgr.updateRecord('srchSearches',stcMain);
variables.DataMgr.insertRecord('srchSelections',stcChosen);
</cfscript>
<cflocation url="#arguments.to#" addtoken="No">
</cffunction>
<cffunction name="getSearchData" access="public" returntype="query" output="no" hint="I return information about past searches.">
<cfargument name="startdate" type="date" required="no">
<cfargument name="enddate" type="date" required="no">
<cfset var qSearches = 0>
<cfquery name="qSearches" datasource="#variables.datasource#">
SELECT Phrase, Count(SearchID) AS numSearches
FROM srchSearches
WHERE 0 = 0
<cfif isDefined("arguments.startdate")>
AND WhenRequested >= #CreateODBCDateTime(arguments.startdate)#
</cfif>
<cfif isDefined("arguments.enddate")>
AND WhenRequested < #CreateODBCDateTime(arguments.enddate)#
</cfif>
GROUP BY Phrase
ORDER BY NumSearches DESC
</cfquery>
<cfreturn qSearches>
</cffunction>
<cffunction name="getLandingPages" access="public" returntype="query" output="no" hint="I return information about the given search phrase.">
<cfargument name="searchterm" type="string" required="yes">
<cfargument name="startdate" type="date" required="no">
<cfargument name="enddate" type="date" required="no">
<cfset var qSearchData = 0>
<cfquery name="qSearchData" datasource="#variables.datasource#">
SELECT Count(SearchID) AS numTimesChosen,LastPageChosen
FROM srchSearches
WHERE Phrase = <cfqueryparam value="#arguments.searchterm#" cfsqltype="CF_SQL_VARCHAR">
<cfif isDefined("arguments.startdate")>
AND WhenRequested >= #CreateODBCDateTime(arguments.startdate)#
</cfif>
<cfif isDefined("arguments.enddate")>
AND WhenRequested < #CreateODBCDateTime(arguments.enddate)#
</cfif>
GROUP BY LastPageChosen
ORDER BY numTimesChosen DESC
</cfquery>
<cfreturn qSearchData>
</cffunction>
<cffunction name="getDirDelim" acess="private" returntype="string" output="no">
<cfset var result = "/">
<cfif NOT StructKeyExists(variables,"dirdelim")>
<cftry>
<cfset variables.dirdelim = CreateObject("java", "java.io.File").separator>
<cfcatch>
<cftry>
<cfif Server.OS.name CONTAINS "Windows">
<cfset variables.dirdelim = "\">
<cfelse>
<cfset variables.dirdelim = "/">
</cfif>
<cfcatch>
<cfif getCurrentTemplatePath() CONTAINS "/">
<cfset variables.dirdelim = "/">
<cfelse>
<cfset variables.dirdelim = "\">
</cfif>
</cfcatch>
</cftry>
</cfcatch>
</cftry>
</cfif>
<cfset result = variables.dirdelim>
<cfreturn result>
</cffunction>
<cffunction name="getDbXml" access="public" returntype="string" output="no" hint="I return the XML for the tables needed for Searcher to work.">
<cfset var tableXML = "">
<cfsavecontent variable="tableXML">
<tables>
<table name="srchSearches">
<field ColumnName="SearchID" CF_DataType="CF_SQL_INTEGER" PrimaryKey="true" Increment="true" />
<field ColumnName="Phrase" CF_DataType="CF_SQL_VARCHAR" Length="180" />
<field ColumnName="WhenRequested" CF_DataType="CF_SQL_DATE" />
<field ColumnName="RecordsReturned" CF_DataType="CF_SQL_INTEGER" />
<field ColumnName="LastPageChosen" CF_DataType="CF_SQL_VARCHAR" Length="180" />
<field ColumnName="Collections" CF_DataType="CF_SQL_VARCHAR" Length="250" />
</table>
<table name="srchSelections">
<field ColumnName="SearchLinkID" CF_DataType="CF_SQL_INTEGER" PrimaryKey="true" Increment="true" />
<field ColumnName="SearchID" CF_DataType="CF_SQL_INTEGER" />
<field ColumnName="PageChosen" CF_DataType="CF_SQL_VARCHAR" Length="180" />
<field ColumnName="WhenChosen" CF_DataType="CF_SQL_DATE" />
</table>
</tables>
</cfsavecontent>
<cfreturn tableXML>
</cffunction>
<cfscript>
/**
* Removes rows from a query.
* Added var col = "";
* No longer using Evaluate. Function is MUCH smaller now.
*
* @param Query Query to be modified
* @param Rows Either a number or a list of numbers
* @return This function returns a query.
* @author Raymond Camden ([email protected])
* @version 2, October 11, 2001
*/
function QueryDeleteRows(Query,Rows) {
var tmp = QueryNew(Query.ColumnList);
var i = 1;
var x = 1;
for(i=1;i lte Query.recordCount; i=i+1) {
if(not ListFind(Rows,i)) {
QueryAddRow(tmp,1);
for(x=1;x lte ListLen(tmp.ColumnList);x=x+1) {
QuerySetCell(tmp, ListGetAt(tmp.ColumnList,x), query[ListGetAt(tmp.ColumnList,x)][i]);
}
}
}
return tmp;
}
function fixQuotes(str) {
//Make sure we have an even number of quotes
var searchstring = ReplaceNoCase(arguments.str,"'","#chr(34)#");
var sQuotePositions = REFind("""[^""]*""",searchstring,1,"true");
if ( NOT StructIsEmpty(sQuotePositions) AND ArrayLen(sQuotePositions.pos) MOD 2 NEQ 0 ) {
searchstring = Reverse(searchstring);
searchstring = Replace(searchstring,"""","");
searchstring = Reverse(searchstring);
}
return searchstring;
}
/**
* Converts a Google-style search string to Verity style.
*
* @param strSearch string to be modified
* @return This function returns a string.
* @author Tim DeMoss
* @version 1, September 10, 2007
*/
function deGooglize(strSearch) {//I convert a Google-style search string to Verity style
var aSections = ArrayNew(1);
var cursor = 1;
var nextQuotePos = 0;
var shortstring = "";
var searchstring = arguments.strSearch;
//Make sure we have an even number of quotes
var sQuotePositions = REFind("""[^""]*""",searchstring,1,"true");
if (NOT StructIsEmpty(sQuotePositions) AND ArrayLen(sQuotePositions.pos) MOD 2 NEQ 0) {
searchstring = Reverse(searchstring);
searchstring = Replace(searchstring,"""","");
searchstring = Reverse(searchstring);
}
//trim all multiple spaces to single spaces
searchstring = REReplace(searchstring,"\s+"," ","ALL");
//convert all ORs to commas
searchstring = ReplaceNoCase(searchstring," OR ",",");
//manipulate the resulting string
while ( cursor LT Len(searchstring) ) {
shortstring = Mid(searchstring,cursor,Len(searchstring)-cursor+1);
if ( Left(Trim(shortstring),1) EQ chr(34) ) {
//Slap that thing into the array (sans quotes)
nextQuotePos = Find("""",searchstring,cursor+1);
ArrayAppend(aSections,Mid(searchstring,cursor+1,nextQuotePos-cursor-1));
//Move cursor to the end of the string we found
cursor = nextQuotePos + 1;
} else {
//find next quote
nextQuotePos = Find("""",searchstring,cursor);
if (nextQuotePos EQ 0) { //no more quotes
nextQuotePos = Len(searchstring) + 1;
}
shortstring = Mid(searchstring,cursor,nextQuotePos-cursor);
// List manipulation
shortstring = Replace(shortstring," ","&","all");
shortstring = ReplaceNoCase(shortstring,"&AND&","&","all");
// Slap result into array
ArrayAppend(aSections,shortstring);
//CFDUMP(aSections);
//Move cursor to the end of the string we found
cursor = nextQuotePos;
}
}
//recreate the search string from stored values in the array
searchstring = ArrayToList(aSections,"&");
//put ANDs in place of &s
return ListChangeDelims(searchstring," AND ","&");
}
</cfscript>
</cfcomponent>