01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.search.impl;
23:
24: import org.jboss.portal.search.FederatedQuery;
25: import org.jboss.portal.search.Query;
26: import org.jboss.portal.search.QueryConversionException;
27: import org.jboss.portal.search.QueryConverter;
28:
29: /**
30: * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
31: * @version $Revision: 8784 $
32: */
33: public class StandardQueryConverter implements QueryConverter {
34:
35: public Query convert(FederatedQuery query)
36: throws QueryConversionException {
37: // org.apache.lucene.search.Query luceneQuery = ((LuceneQuery) query).getLuceneQuery();
38: // return convertFromLucene(luceneQuery);
39: return null;
40: }
41:
42: /*
43: public Query convertFromLucene(org.apache.lucene.search.Query luceneQuery) throws QueryConversionException
44: {
45: if (luceneQuery == null)
46: {
47: return null;
48: }
49: else if (luceneQuery instanceof org.apache.lucene.search.TermQuery)
50: {
51: return convertTermQuery((org.apache.lucene.search.TermQuery)luceneQuery);
52: }
53: else if (luceneQuery instanceof org.apache.lucene.search.BooleanQuery)
54: {
55: return convertBooleanQuery((org.apache.lucene.search.BooleanQuery)luceneQuery);
56: }
57: else
58: {
59: throw new QueryConversionException("Unknown query type: " + luceneQuery.getClass());
60: }
61: }
62:
63: public Query convertTermQuery(org.apache.lucene.search.TermQuery luceneQuery)
64: {
65: org.apache.lucene.index.Term term = ((org.apache.lucene.search.TermQuery)luceneQuery).getTerm();
66: return new TermQuery(new Term(term.field(), term.text()));
67: }
68:
69: public Query convertBooleanQuery(org.apache.lucene.search.BooleanQuery luceneQuery)
70: {
71: org.apache.lucene.search.BooleanQuery luceneBooleanQuery = (org.apache.lucene.search.BooleanQuery)luceneQuery;
72: org.apache.lucene.search.BooleanClause[] luceneClauses = luceneBooleanQuery.getClauses();
73: List clauses = new ArrayList();
74: for (int i=0; i<luceneClauses.length; i++)
75: {
76: org.apache.lucene.search.BooleanClause luceneClause = luceneClauses[i];
77: try
78: {
79: clauses.add(new BooleanClause(convertFromLucene(luceneClause.query), luceneClause.required, luceneClause.prohibited));
80: }
81: catch (QueryConversionException e)
82: {
83: e.printStackTrace();
84: }
85: }
86: return new BooleanQuery(clauses);
87: }
88: */
89: }
|