My favorites | Sign in
Project Logo
                
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
/**
* DSM - Distributed Search Manager
* Developed by Milspec Research International Pty Ltd
* $Author: bslattery $
* $Revision: 1.4 $
* $Date: 2007/08/22 05:15:50 $
* (c)Copyright 2004
* education.au limited
* DEST
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the names education.au limited, DEST nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
* To the extent permitted by law, the copyright owners of this software and
* its contributors:
* (i) exclude all warranties in relation to the software; and
* (ii) exclude liability for all losses, costs, expenses and damages arising
* in any way from the use of the software whether arising from or in
* relation to breach of contract, negligence or any other tort, in equity
* or otherwise. If the software is in breach of a warranty which is
* implied by law, the copyright owners and contributors liability is
* limited to the replacement of the software.
*
* @author gsingh
*/

package au.edu.educationau.opensource.dsm.adapters;

import java.io.Reader;
import java.util.ArrayList;

import au.edu.educationau.opensource.dsm.DeusExMachina;
import au.edu.educationau.opensource.dsm.adapters.contenthandler.SolrContentHandler;
import au.edu.educationau.opensource.dsm.adapters.querygenerator.QueryGenerator;
import au.edu.educationau.opensource.dsm.adapters.querygenerator.SolrQueryGenerator;
import au.edu.educationau.opensource.dsm.cache.DiskCacheEntry;
import au.edu.educationau.opensource.dsm.obj.SearchCriteria;
import au.edu.educationau.opensource.dsm.service.PropertiesService;
import au.edu.educationau.opensource.dsm.util.Flog;
import au.edu.educationau.opensource.dsm.util.StringUtils;
import au.edu.educationau.opensource.dsm.worker.ResultSetUnifier;

/**
* Solr search engine searching. Parses the standard Solr XML result to extract
* result info.
*/

public class SolrSearchAdapterImpl extends SearchAdapter {

/** Parent constructor */
public SolrSearchAdapterImpl() {
super();
}

/**
* See the SearchAdapter abstract method doPrime
*
* @exception Throwable
*/
public void doPrime() throws Throwable {
SearchCriteria criteria = getSearchCriteria();
// addToURLBuffer("qt=dismax&start=0");
// addToURLBuffer("qt=standard&start=0");
addToURLBuffer("start=0");
if (super.getProperties().getBatchSize() != 0 && StringUtils.isEmpty(criteria.getCustomParamValue(getProperties().getAdapterCode() + ".rows"))) {
addToURLBuffer("&rows=" + getProperties().getBatchSize());
}
addToURLBuffer(generateSearchQuery(criteria, getProperties()));
}

private String generateSearchQuery(SearchCriteria criteria, SearchAdapterProperties props) {


String queryGenerator = PropertiesService.getStringProperty(props.getAdapterCode() + ".query.generator", SolrQueryGenerator.class.getName());
try {
Class generatorClass = Class.forName(queryGenerator);
QueryGenerator generator = (QueryGenerator) generatorClass.newInstance();
return generator.generateQueryParams(criteria, props);
} catch (Exception e) {
Flog.error(toString(), "error generating query string", e);
return "";
}
}

/**
* See the SearchAdapter abstract method doPerform
*
* @exception Throwable
*/
public ArrayList doPerform() throws Throwable {
SolrContentHandler cHandler = new SolrContentHandler();
cHandler.setWebsiteURL(super.getProperties().getWebsiteURL());
cHandler.setSearchAdapterProperties(super.getProperties());
cHandler.setSearchCriteria(super.getSearchCriteria());
DiskCacheEntry entry = DeusExMachina._DiskCache().getEntry(super.getAugmentedSearchURL());
if (null != entry) {
Reader reader = entry.getBufferedReader();
if (null != reader) {
cHandler = (SolrContentHandler) ResultSetUnifier.processXML(reader, cHandler, "UTF-8");
}
}
ArrayList batch = cHandler.getResults();
super.setTheoreticalAvailableResults(cHandler.getFound());
super.setFacetQueryCounts(cHandler.getFacetQueryCounts());
return batch;
}

/**
* See the SearchAdapter abstract method doNextBatch
*
* @exception Throwable
*/
public boolean doNextBatch() throws Throwable {
return false;
}

/**
* See the SearchAdapter abstract method doStopNice
*
* @exception Throwable
*/
public void doStopNice() throws Throwable {
// does nothing here
}

/**
* See the SearchAdapter abstract method doStopForce
*
* @exception Throwable
*/
public void doStopForce() throws Throwable {
// does nothing here
}

/** Class display string */
public String toString() {
return "o.m.d.a.SolrSearchAdapterImpl";
}

} // -- EOF
Show details Hide details

Change log

r34 by nick.lothian on Mar 02, 2008   Diff
use class name instead of literal
Go to: 
Project members, sign in to write a code review

Older revisions

r15 by nick.lothian on Jan 09, 2008   Diff
Initial import.
All revisions of this file

File info

Size: 5311 bytes, 147 lines
Hosted by Google Code