Source Code Cross Referenced for LiusQuery.java in  » Search-Engine » Lius-0.4 » ca » ulaval » bibl » lius » search » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Search Engine » Lius 0.4 » ca.ulaval.bibl.lius.search 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:         * LIUS - Lucene Index Update and Search
004:         * http://sourceforge.net/projects/lius/
005:         *
006:         * Copyright (c) 2005, Laval University Library.  All rights reserved.
007:         * 
008:         * This library is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU Lesser General Public
010:         * License as published by the Free Software Foundation; either
011:         * version 2.1 of the License, or (at your option) any later version.
012:         * 
013:         * This library is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         * Lesser General Public License for more details.
017:         * 
018:         * You should have received a copy of the GNU Lesser General Public
019:         * License along with this library; if not, write to the Free Software
020:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
021:         */
022:
023:        package ca.ulaval.bibl.lius.search;
024:
025:        import java.lang.reflect.Constructor;
026:
027:        import org.apache.log4j.Logger;
028:        import org.apache.lucene.index.Term;
029:        import org.apache.lucene.queryParser.MultiFieldQueryParser;
030:        import org.apache.lucene.queryParser.ParseException;
031:        import org.apache.lucene.queryParser.QueryParser;
032:        import org.apache.lucene.search.Query;
033:        import org.apache.lucene.search.RangeQuery;
034:
035:        import ca.ulaval.bibl.lius.Lucene.AnalyzerFactory;
036:        import ca.ulaval.bibl.lius.config.LiusConfig;
037:
038:        /**
039:         * 
040:         * Classe permettant de créer des objets de type Query.
041:         * 
042:         * <br/><br/>
043:         * 
044:         * Class that creates Query objects.
045:         * 
046:         * @author Rida Benjelloun (rida.benjelloun@bibl.ulaval.ca)
047:         *  
048:         */
049:
050:        public class LiusQuery {
051:
052:            private static LiusQuery liusQueryInst;
053:
054:            private Query q = null;
055:
056:            static Logger logger = Logger.getRootLogger();
057:
058:            /**
059:             * 
060:             * Méthode utilisant la réflexion et permettant de créer des objets de type
061:             * Query,
062:             * 
063:             * dont le constructeur prend un objet de type Term.
064:             * 
065:             * L'objet Term est construit à partir du nom du champs spécifié dans le
066:             * 
067:             * fichier de configuration et de la valeur exprimée sous forme de paramètre
068:             * 
069:             * "searchExp"de la méthode createQueryTerm.
070:             * 
071:             * <br/><br/>
072:             * 
073:             * The method uses reflection which creates object of type Query which
074:             * constructor takes
075:             * 
076:             * an object of type Term as parameter. The Term object is constructed from
077:             * 
078:             * the name of the specified field in the configuration file and the value
079:             * of
080:             * 
081:             * "searchExp" parameter.
082:             *  
083:             */
084:
085:            public Query createQueryTerm(LiusConfig xc, String searchExp) {
086:
087:                try {
088:
089:                    Class classe = Class.forName(xc.getQueryTermClass());
090:
091:                    Constructor[] con = classe.getConstructors();
092:
093:                    for (int i = 0; i < con.length; i++) {
094:
095:                        Class[] conParam = con[i].getParameterTypes();
096:
097:                        for (int j = 0; j < conParam.length; j++)
098:
099:                            if (conParam[j].getName().equals(
100:                                    "org.apache.lucene.index.Term")) {
101:
102:                                // Création de l'objet Term
103:
104:                                Term t = new Term(xc.getTermFiled(), searchExp);
105:
106:                                q = (Query) con[i]
107:                                        .newInstance(new Object[] { t });
108:
109:                            }
110:
111:                    }
112:
113:                }
114:
115:                catch (ClassNotFoundException e) {
116:
117:                    logger.error("La classe n'a pas été trouvée"
118:                            + e.getMessage());
119:
120:                }
121:
122:                catch (InstantiationException e) {
123:
124:                    logger
125:                            .error("La classe est soit abstraite, soit une interface"
126:                                    +
127:
128:                                    e.getMessage());
129:
130:                }
131:
132:                catch (IllegalAccessException e) {
133:
134:                    logger.error("La classe n'est pas accessible"
135:                            + e.getMessage());
136:
137:                }
138:
139:                catch (java.lang.reflect.InvocationTargetException e) {
140:
141:                    logger
142:                            .error(" Exception déclenchée si le constructeur invoqué"
143:                                    +
144:
145:                                    e.getMessage());
146:
147:                }
148:
149:                catch (IllegalArgumentException e) {
150:
151:                    logger.error(" Mauvais type de paramètres "
152:                            + e.getMessage());
153:
154:                }
155:
156:                return q;
157:
158:            }
159:
160:            /**
161:             * 
162:             * Création d'un objet Query de type MultiFieldQueryParser à partir du
163:             * 
164:             * fichier de configuration.
165:             * 
166:             * <br/><br/ <
167:             * 
168:             * Creation of an object Query of type MultiFieldQueryParser from the
169:             * 
170:             * configuration file.
171:             *  
172:             */
173:
174:            public Query createMultiFieldQueryParser(LiusConfig xc,
175:                    String searchExp) {
176:
177:                try {
178:
179:                    q = MultiFieldQueryParser.parse(searchExp, xc
180:                            .getSearchFields(),
181:
182:                    AnalyzerFactory.getAnalyzer(xc));
183:
184:                }
185:
186:                catch (ParseException e) {
187:
188:                    logger.error(e.getMessage());
189:
190:                }
191:
192:                return q;
193:
194:            }
195:
196:            /**
197:             * 
198:             * Création d'un objet Query de type QueryParser à partir du fichier de
199:             * 
200:             * configuration.
201:             * 
202:             * <br/><br/>
203:             * 
204:             * Creation of a Query object of type QueryParser from the configuration
205:             * file.
206:             *  
207:             */
208:
209:            public Query createQueryParser(LiusConfig xc, String searchExp) {
210:
211:                try {
212:
213:                    q = QueryParser.parse(searchExp,
214:                            xc.getDefaultSearchField(),
215:
216:                            AnalyzerFactory.getAnalyzer(xc));
217:
218:                }
219:
220:                catch (ParseException e) {
221:
222:                    logger.error(e.getMessage());
223:
224:                }
225:
226:                return q;
227:
228:            }
229:
230:            /**
231:             * 
232:             * Méthode permettant de créer un objet Query en fonction de l'élément
233:             * 
234:             * XML trouvé dans le fichier de configuration.
235:             * 
236:             * <br/><br/>
237:             * 
238:             * Method that creates a Query Object relative to the XML element found in
239:             * the
240:             * 
241:             * configuration file.
242:             *  
243:             */
244:
245:            public Query getQueryFactory(String type, LiusConfig xc,
246:                    String searchExp) {
247:
248:                if (type.equals("queryTerm"))
249:
250:                    q = createQueryTerm(xc, searchExp);
251:
252:                else if (type.equals("queryParser"))
253:
254:                    q = createQueryParser(xc, searchExp);
255:
256:                else if (type.equals("multiFieldQueryParser"))
257:
258:                    q = createMultiFieldQueryParser(xc, searchExp);
259:
260:                return q;
261:
262:            }
263:
264:            /**
265:             * 
266:             * Création d'un objet Query de type RangeQuery à partir du fichier
267:             * 
268:             * de configuration.
269:             * 
270:             * <br/><br/>
271:             * 
272:             * Creation of a Query object of type RangeQuery from the configuration
273:             * file.
274:             *  
275:             */
276:
277:            public Query createRangeQuery(LiusConfig xc,
278:                    String lowerSearchExp1,
279:
280:                    String uppersearchExp2) {
281:
282:                String[] values = xc.getRangeQueryFileds();
283:
284:                boolean inclusive = true;
285:
286:                if (values[1].equalsIgnoreCase("true")) {
287:
288:                    inclusive = true;
289:
290:                }
291:
292:                else {
293:
294:                    inclusive = false;
295:
296:                }
297:
298:                Term t1 = new Term(values[0], lowerSearchExp1);
299:
300:                Term t2 = new Term(values[0], uppersearchExp2);
301:
302:                q = new RangeQuery(t1, t2, inclusive);
303:
304:                return q;
305:
306:            }
307:
308:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.