Source Code Cross Referenced for LuceneSettings.java in  » Search-Engine » compass-2.0 » org » compass » core » lucene » engine » 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 » compass 2.0 » org.compass.core.lucene.engine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2006 the original author or authors.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.compass.core.lucene.engine;
018:
019:        import org.apache.commons.logging.Log;
020:        import org.apache.commons.logging.LogFactory;
021:        import org.apache.lucene.index.IndexWriter;
022:        import org.apache.lucene.store.Lock;
023:        import org.compass.core.CompassTransaction.TransactionIsolation;
024:        import org.compass.core.Property;
025:        import org.compass.core.config.CompassEnvironment;
026:        import org.compass.core.config.CompassSettings;
027:        import org.compass.core.engine.SearchEngineException;
028:        import org.compass.core.lucene.LuceneEnvironment;
029:        import org.compass.core.util.ClassUtils;
030:
031:        /**
032:         * A helper methods that holds most of the Lucene specific properties, initlizes
033:         * from {@link org.compass.core.config.CompassSettings}.
034:         *
035:         * @author kimchy
036:         */
037:        public class LuceneSettings {
038:
039:            private static final Log log = LogFactory
040:                    .getLog(LuceneSettings.class);
041:
042:            private CompassSettings settings;
043:
044:            private String connection;
045:
046:            private String subContext;
047:
048:            private String defaultSearchPropery;
049:
050:            private String allProperty;
051:
052:            private Property.TermVector allPropertyTermVector;
053:
054:            private boolean allPropertyBoostSupport;
055:
056:            private String aliasProperty;
057:
058:            private String extendedAliasProperty;
059:
060:            private TransactionIsolation transactionIsolation;
061:
062:            private Class transactionIsolationClass;
063:
064:            private int maxMergeDocs;
065:
066:            private int mergeFactor;
067:
068:            private boolean useCompoundFile;
069:
070:            private int maxFieldLength;
071:
072:            private int maxBufferedDocs;
073:
074:            private int maxBufferedDeletedTerms;
075:
076:            private int termIndexInterval;
077:
078:            private double ramBufferSize;
079:
080:            private long transactionLockTimout;
081:
082:            private long cacheInvalidationInterval;
083:
084:            private long indexManagerScheduleInterval;
085:
086:            private boolean waitForCacheInvalidationOnIndexOperation;
087:
088:            private String lockDir;
089:
090:            private boolean clearCacheOnCommit;
091:
092:            public void configure(CompassSettings settings)
093:                    throws SearchEngineException {
094:                this .settings = settings;
095:                connection = settings.getSetting(CompassEnvironment.CONNECTION);
096:                if (connection == null) {
097:                    throw new SearchEngineException(
098:                            "Lucene connection must be set in the settings. Please set ["
099:                                    + CompassEnvironment.CONNECTION + "]");
100:                }
101:                subContext = settings
102:                        .getSetting(CompassEnvironment.CONNECTION_SUB_CONTEXT);
103:                if (log.isDebugEnabled()) {
104:                    log.debug("Using connection [" + connection + "]["
105:                            + subContext + "]");
106:                }
107:                // the alias property
108:                aliasProperty = settings.getSetting(
109:                        CompassEnvironment.Alias.NAME,
110:                        CompassEnvironment.Alias.DEFAULT_NAME);
111:                if (log.isDebugEnabled()) {
112:                    log.debug("Using alias property [" + aliasProperty + "]");
113:                }
114:
115:                extendedAliasProperty = settings.getSetting(
116:                        CompassEnvironment.Alias.EXTENDED_ALIAS_NAME,
117:                        CompassEnvironment.Alias.DEFAULT_EXTENDED_ALIAS_NAME);
118:                if (log.isDebugEnabled()) {
119:                    log.debug("Using extended alias property ["
120:                            + extendedAliasProperty + "]");
121:                }
122:
123:                // get the all property
124:                allProperty = settings.getSetting(CompassEnvironment.All.NAME,
125:                        CompassEnvironment.All.DEFAULT_NAME);
126:                if (log.isDebugEnabled()) {
127:                    log.debug("Using default all property [" + allProperty
128:                            + "]");
129:                }
130:                String allPropertyTermVectorSettings = settings.getSetting(
131:                        CompassEnvironment.All.TERM_VECTOR, "no");
132:                if (log.isDebugEnabled()) {
133:                    log.debug("Using all property term vector ["
134:                            + allPropertyTermVectorSettings + "]");
135:                }
136:                allPropertyBoostSupport = settings.getSettingAsBoolean(
137:                        CompassEnvironment.All.BOOST_SUPPORT, true);
138:                if (log.isDebugEnabled()) {
139:                    log.debug("All property boost support is ["
140:                            + allPropertyBoostSupport + "]");
141:                }
142:                if ("no".equals(allPropertyTermVectorSettings)) {
143:                    allPropertyTermVector = Property.TermVector.NO;
144:                } else if ("yes".equals(allPropertyTermVectorSettings)) {
145:                    allPropertyTermVector = Property.TermVector.YES;
146:                } else if ("positions".equals(allPropertyTermVectorSettings)) {
147:                    allPropertyTermVector = Property.TermVector.WITH_POSITIONS;
148:                } else if ("offsets".equals(allPropertyTermVectorSettings)) {
149:                    allPropertyTermVector = Property.TermVector.WITH_OFFSETS;
150:                } else if ("positions_offsets"
151:                        .equals(allPropertyTermVectorSettings)) {
152:                    allPropertyTermVector = Property.TermVector.WITH_POSITIONS_OFFSETS;
153:                } else {
154:                    throw new SearchEngineException(
155:                            "Unrecognized term vector setting for the all property ["
156:                                    + allPropertyTermVectorSettings + "]");
157:                }
158:                // get the default search term, defaults to the all property
159:                defaultSearchPropery = settings.getSetting(
160:                        LuceneEnvironment.DEFAULT_SEARCH, allProperty);
161:                if (log.isDebugEnabled()) {
162:                    log.debug("Using default search property ["
163:                            + defaultSearchPropery + "]");
164:                }
165:                // build the trasnaction
166:                String transIsolationSetting = settings
167:                        .getSetting(
168:                                CompassEnvironment.Transaction.ISOLATION,
169:                                CompassEnvironment.Transaction.ISOLATION_READ_COMMITTED);
170:                if (transIsolationSetting
171:                        .equalsIgnoreCase(CompassEnvironment.Transaction.ISOLATION_NONE)) {
172:                    transactionIsolation = TransactionIsolation.READ_COMMITTED;
173:                } else if (transIsolationSetting
174:                        .equalsIgnoreCase(CompassEnvironment.Transaction.ISOLATION_READ_UNCOMMITTED)) {
175:                    transactionIsolation = TransactionIsolation.READ_COMMITTED;
176:                } else if (transIsolationSetting
177:                        .equalsIgnoreCase(CompassEnvironment.Transaction.ISOLATION_READ_COMMITTED)) {
178:                    transactionIsolation = TransactionIsolation.READ_COMMITTED;
179:                } else if (transIsolationSetting
180:                        .equalsIgnoreCase(CompassEnvironment.Transaction.ISOLATION_REPEATABLE_READ)) {
181:                    transactionIsolation = TransactionIsolation.READ_COMMITTED;
182:                } else if (transIsolationSetting
183:                        .equalsIgnoreCase(CompassEnvironment.Transaction.ISOLATION_SERIALIZABLE)) {
184:                    transactionIsolation = TransactionIsolation.SERIALIZABLE;
185:                } else if (transIsolationSetting
186:                        .equalsIgnoreCase(CompassEnvironment.Transaction.ISOLATION_BATCH_INSERT)) {
187:                    transactionIsolation = TransactionIsolation.BATCH_INSERT;
188:                } else if (transIsolationSetting
189:                        .equalsIgnoreCase(CompassEnvironment.Transaction.ISOLATION_LUCENE)) {
190:                    transactionIsolation = TransactionIsolation.LUCENE;
191:                }
192:                String transIsolationClassSetting = settings.getSetting(
193:                        CompassEnvironment.Transaction.ISOLATION_CLASS, null);
194:                if (transIsolationClassSetting != null) {
195:                    try {
196:                        transactionIsolationClass = ClassUtils.forName(
197:                                transIsolationClassSetting, settings
198:                                        .getClassLoader());
199:                    } catch (ClassNotFoundException e) {
200:                        throw new SearchEngineException(
201:                                "Can't find transaction class ["
202:                                        + transIsolationClassSetting + "]", e);
203:                    }
204:                }
205:                // lucene specifics parameters
206:                transactionLockTimout = settings.getSettingAsLong(
207:                        LuceneEnvironment.Transaction.LOCK_TIMEOUT, 10) * 1000;
208:                if (log.isDebugEnabled()) {
209:                    log.debug("Using transaction lock timeout ["
210:                            + transactionLockTimout + "ms]");
211:                }
212:                IndexWriter.setDefaultWriteLockTimeout(transactionLockTimout);
213:
214:                Lock.LOCK_POLL_INTERVAL = settings.getSettingAsLong(
215:                        LuceneEnvironment.Transaction.LOCK_POLL_INTERVAL, 100);
216:                if (log.isDebugEnabled()) {
217:                    log.debug("Using lock poll interval ["
218:                            + Lock.LOCK_POLL_INTERVAL + "ms]");
219:                }
220:
221:                lockDir = settings.getSetting("compass.transaction.lockDir");
222:                if (lockDir != null) {
223:                    throw new IllegalArgumentException(
224:                            "compass.transaction.lockDir setting is no longer supported. "
225:                                    + "The lock by default is stored in the index directory now, and can be conrolled by using LockFactory");
226:                }
227:
228:                maxMergeDocs = settings.getSettingAsInt(
229:                        LuceneEnvironment.SearchEngineIndex.MAX_MERGE_DOCS,
230:                        Integer.MAX_VALUE);
231:                useCompoundFile = settings.getSettingAsBoolean(
232:                        LuceneEnvironment.SearchEngineIndex.USE_COMPOUND_FILE,
233:                        true);
234:                if (log.isDebugEnabled()) {
235:                    log
236:                            .debug("Using compound format [" + useCompoundFile
237:                                    + "]");
238:                }
239:
240:                clearCacheOnCommit = settings.getSettingAsBoolean(
241:                        LuceneEnvironment.Transaction.CLEAR_CACHE_ON_COMMIT,
242:                        true);
243:                if (log.isDebugEnabled()) {
244:                    log.debug("Using clear cache on commit ["
245:                            + clearCacheOnCommit + "]");
246:                }
247:
248:                // pure lucene transaction settings
249:                mergeFactor = settings.getSettingAsInt(
250:                        LuceneEnvironment.SearchEngineIndex.MERGE_FACTOR, 10);
251:                maxBufferedDocs = settings.getSettingAsInt(
252:                        LuceneEnvironment.SearchEngineIndex.MAX_BUFFERED_DOCS,
253:                        IndexWriter.DISABLE_AUTO_FLUSH);
254:                maxBufferedDeletedTerms = settings
255:                        .getSettingAsInt(
256:                                LuceneEnvironment.SearchEngineIndex.MAX_BUFFERED_DELETED_TERMS,
257:                                IndexWriter.DISABLE_AUTO_FLUSH);
258:                termIndexInterval = settings
259:                        .getSettingAsInt(
260:                                LuceneEnvironment.SearchEngineIndex.TERM_INDEX_INTERVAL,
261:                                IndexWriter.DEFAULT_TERM_INDEX_INTERVAL);
262:                maxFieldLength = settings.getSettingAsInt(
263:                        LuceneEnvironment.SearchEngineIndex.MAX_FIELD_LENGTH,
264:                        IndexWriter.DEFAULT_MAX_FIELD_LENGTH);
265:
266:                ramBufferSize = settings.getSettingAsDouble(
267:                        LuceneEnvironment.SearchEngineIndex.RAM_BUFFER_SIZE,
268:                        IndexWriter.DEFAULT_RAM_BUFFER_SIZE_MB);
269:
270:                // cach invalidation settings
271:                cacheInvalidationInterval = settings
272:                        .getSettingAsLong(
273:                                LuceneEnvironment.SearchEngineIndex.CACHE_INTERVAL_INVALIDATION,
274:                                5000);
275:                if (log.isDebugEnabled()) {
276:                    log.debug("Using cach invalidation interval ["
277:                            + cacheInvalidationInterval + "ms]");
278:                }
279:                indexManagerScheduleInterval = (long) (settings
280:                        .getSettingAsFloat(
281:                                LuceneEnvironment.SearchEngineIndex.INDEX_MANAGER_SCHEDULE_INTERVAL,
282:                                60.0f) * 1000);
283:                if (log.isDebugEnabled()) {
284:                    log.debug("Using index manager schedule interval ["
285:                            + indexManagerScheduleInterval + "ms]");
286:                }
287:
288:                waitForCacheInvalidationOnIndexOperation = settings
289:                        .getSettingAsBoolean(
290:                                LuceneEnvironment.SearchEngineIndex.WAIT_FOR_CACHE_INVALIDATION_ON_INDEX_OPERATION,
291:                                false);
292:                if (log.isDebugEnabled()) {
293:                    log
294:                            .debug("Wait for cahce invalidation on index operatrion is set to ["
295:                                    + waitForCacheInvalidationOnIndexOperation
296:                                    + "]");
297:                }
298:            }
299:
300:            public CompassSettings getSettings() {
301:                return this .settings;
302:            }
303:
304:            public String getAllProperty() {
305:                return allProperty;
306:            }
307:
308:            public String getAliasProperty() {
309:                return aliasProperty;
310:            }
311:
312:            public String getExtendedAliasProperty() {
313:                return extendedAliasProperty;
314:            }
315:
316:            public TransactionIsolation getTransactionIsolation() {
317:                return transactionIsolation;
318:            }
319:
320:            public Class getTransactionIsolationClass() {
321:                return transactionIsolationClass;
322:            }
323:
324:            public int getMaxMergeDocs() {
325:                return maxMergeDocs;
326:            }
327:
328:            public int getMergeFactor() {
329:                return mergeFactor;
330:            }
331:
332:            public boolean isUseCompoundFile() {
333:                return useCompoundFile;
334:            }
335:
336:            public int getMaxFieldLength() {
337:                return maxFieldLength;
338:            }
339:
340:            public int getMaxBufferedDocs() {
341:                return maxBufferedDocs;
342:            }
343:
344:            public int getMaxBufferedDeletedTerms() {
345:                return maxBufferedDeletedTerms;
346:            }
347:
348:            public int getTermIndexInterval() {
349:                return termIndexInterval;
350:            }
351:
352:            public double getRamBufferSize() {
353:                return ramBufferSize;
354:            }
355:
356:            public String getDefaultSearchPropery() {
357:                return defaultSearchPropery;
358:            }
359:
360:            public String getConnection() {
361:                return connection;
362:            }
363:
364:            public Property.TermVector getAllPropertyTermVector() {
365:                return allPropertyTermVector;
366:            }
367:
368:            public boolean isAllPropertyBoostSupport() {
369:                return allPropertyBoostSupport;
370:            }
371:
372:            public long getTransactionLockTimout() {
373:                return transactionLockTimout;
374:            }
375:
376:            public long getCacheInvalidationInterval() {
377:                return cacheInvalidationInterval;
378:            }
379:
380:            public String getLockDir() {
381:                return lockDir;
382:            }
383:
384:            public long getIndexManagerScheduleInterval() {
385:                return indexManagerScheduleInterval;
386:            }
387:
388:            public boolean isWaitForCacheInvalidationOnIndexOperation() {
389:                return waitForCacheInvalidationOnIndexOperation;
390:            }
391:
392:            public boolean isClearCacheOnCommit() {
393:                return this .clearCacheOnCommit;
394:            }
395:
396:            public String getSubContext() {
397:                return subContext;
398:            }
399:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.