001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.db;
007:
008: import com.sun.portal.search.rdm.*;
009: import com.sun.portal.search.soif.*;
010: import com.sun.portal.search.util.*;
011: import com.sun.portal.search.demo.*;
012:
013: import java.util.*;
014: import java.io.*;
015:
016: /**
017: *
018: * Search engine interface implementation for searching a remote RDM server
019: *
020: */
021: public class RemoteRDMDb implements RDMDb {
022:
023: String rdmserverurl;
024: String rdmserverdb;
025: String defaultView = "score,url,hl-url,hl-description,title,hl-title,classification,hl-classification";
026:
027: /**
028: * Store - creates a transaction for atomic indexing, if none supplied.
029: * @param st Token for search
030: * @param insoif SOIF document
031: * @param view Set of Attributes
032: * @param flags Options
033: * @param t RDM transaction
034: * @throws RDMException
035: */
036: public void store(SToken st, SOIF insoif, Set view, int flags,
037: RDMTransaction t) throws RDMException {
038: throw new RDMException("RemoteRDMDb.store(): not implemented");
039: }
040:
041: /**
042: * Empty the database
043: * @param st Token for search
044: * @param t RDM transaction handle
045: * @throws RDMException
046: */
047: public int purge(SToken st, RDMTransaction t) throws RDMException {
048: throw new RDMException("RemoteRDMDb.purge(): not implemented");
049: }
050:
051: /**
052: * Open a database
053: * @param st Token for search
054: * @param rootdir Database home dir
055: * @param dbname Name of database from root database
056: * @param rw RDMDb.WRITER or RDMDb.WRCREAT or RDMDb.READER
057: * @param mode Unix mode
058: * @throws RDMException
059: */
060: public void open(SToken st, String rootdir, String dbname, int rw,
061: int mode) throws RDMException {
062: SOIF dbsoif = DbManager.getRootDbEntry(st, dbname);
063: rdmserverurl = dbsoif.getValue("rdmserverurl");
064: rdmserverdb = dbsoif.getValue("databasename");
065: String defview = dbsoif.getValue("defaultView");
066: if (defview != null)
067: defaultView = defview;
068: }
069:
070: /**
071: * Close database and index extents
072: * @param st Token for search
073: * @throws RDMException
074: */
075: public void close(SToken st) throws RDMException {
076: ;//do nothing
077: }
078:
079: /**
080: * Obtain the name for the search engine interface
081: * @return the name of the search engine activity
082: */
083: public String getName() {
084: return "RemoteRDM Search";
085: }
086:
087: /**
088: * Submit the query to the search engine
089: * @param st Token for search
090: * @param queryString Search query
091: * @param numHits Number of hits
092: * @param view Set of attributes to be retrieved
093: * @param sortOrder Order for sorting the results
094: * @param t RDM transaction handle
095: * @return RDMResultSet
096: * @throws RDMException
097: */
098: public RDMResultSet search(SToken st, String query, int numHits,
099: Set view, String sortOrder, RDMTransaction t)
100: throws RDMException {
101:
102: Search s;
103:
104: try {
105: String csview = "";
106:
107: if (view != null) {
108: for (Iterator i = view.iterator(); i.hasNext();) {
109: csview = csview + (String) i.next();
110: if (i.hasNext())
111: csview += ",";
112: }
113: } else {
114: // view can be null even if the client sets a view, because
115: // it is not always passed down (in the case of rdmgr), rather,
116: // it is applied after results are pulled from the databse -
117: // we need to change that and always do it down here in the
118: // db class. Here we will set a default view to avoid retrieving
119: // everything from the remote server. This view can be configured
120: // in the federated db.
121: csview = defaultView;
122: }
123:
124: if (csview.equals(""))
125: csview = null;
126:
127: s = new Search(query, csview, sortOrder, 1, numHits,
128: "search", rdmserverdb, rdmserverurl, null);
129: s.doQuery();
130: } catch (Exception e) {
131: throw new RDMException(e);
132: }
133:
134: RemoteRDMResultSet rs = new RemoteRDMResultSet(st, this , query,
135: t);
136: rs.setRemoteRDMSearchResult(s);
137: return rs;
138:
139: }
140:
141: /**
142: * Get search count
143: * @return number of docs.
144: */
145: public int count(SToken st, RDMTransaction t) throws RDMException {
146: return 250000000;
147: }
148:
149: /**
150: * Delete RD from database
151: * @param st Token for search
152: * @param s SOIF document
153: * @param view Set of attributes
154: * @param flags Options
155: * @param t RDM transaction handle
156: * @throws RDMException
157: */
158: public void delete(SToken st, SOIF s, Set view, int flags,
159: RDMTransaction t) throws RDMException {
160: throw new RDMException("RemoteRDMDb.delete() not implemented");
161: }
162:
163: /**
164: * Update an RD with attributes set in View
165: * @param st Token for search
166: * @param insoif SOIF document
167: * @param view Set of Attributes
168: * @param flags Options
169: * @param t RDM transaction
170: * @throws RDMException
171: */
172: public void update(SToken st, SOIF insoif, Set view, int flags,
173: RDMTransaction t) throws RDMException {
174: throw new RDMException("RemoteRDMDb.update() not implemented");
175: }
176:
177: /**
178: * Retrieve RD from database, filtered by view
179: * @param st Token for search
180: * @param url URL string
181: * @param view Set of Attributes
182: * @param flags Options
183: * @param t RDM transaction
184: * @throws RDMException
185: */
186: public SOIF fetch(SToken st, String url, Set view, int flags,
187: RDMTransaction t) throws RDMException {
188: throw new RDMException("RemoteRDMDb.fetch() not implemented");
189: }
190:
191: /**
192: * Optimize the db
193: * @param st Token for search
194: * @throws RDMException
195: */
196: public void optimize(SToken st) throws RDMException {
197: throw new RDMException("RemoteRDMDb.optimize() not implemented");
198: }
199:
200: /**
201: * Batch Index
202: * @param st Token for search
203: * @throws RDMException
204: */
205: public void indexBatch(SToken st) throws RDMException {
206: throw new RDMException(
207: "RemoteRDMDb.indexBatch() not implemented");
208: }
209:
210: /**
211: * Recover the db - must be run stand alone (ie, no one else has the db open)
212: * @param st Token for search
213: * @param dbhome Database home dir
214: * @param fatal Option
215: * @throws RDMException
216: */
217: public void recover(SToken st, String dbhome, boolean fatal)
218: throws RDMException {
219: throw new RDMException("RemoteRDMDb.recover() not implemented");
220: }
221:
222: }
|