Source Code Cross Referenced for ExtendedFieldCacheImpl.java in  » Net » lucene-connector » org » apache » lucene » 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 » Net » lucene connector » org.apache.lucene.search 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.lucene.search;
002:
003:        import org.apache.lucene.index.IndexReader;
004:        import org.apache.lucene.index.Term;
005:        import org.apache.lucene.index.TermDocs;
006:        import org.apache.lucene.index.TermEnum;
007:
008:        import java.io.IOException;
009:
010:        /**
011:         *
012:         *
013:         **/
014:        class ExtendedFieldCacheImpl extends FieldCacheImpl implements 
015:                ExtendedFieldCache {
016:            private static final LongParser LONG_PARSER = new LongParser() {
017:                public long parseLong(String value) {
018:                    return Long.parseLong(value);
019:                }
020:            };
021:
022:            private static final DoubleParser DOUBLE_PARSER = new DoubleParser() {
023:                public double parseDouble(String value) {
024:                    return Double.parseDouble(value);
025:                }
026:            };
027:
028:            public long[] getLongs(IndexReader reader, String field)
029:                    throws IOException {
030:                return getLongs(reader, field, LONG_PARSER);
031:            }
032:
033:            // inherit javadocs
034:            public long[] getLongs(IndexReader reader, String field,
035:                    LongParser parser) throws IOException {
036:                return (long[]) longsCache
037:                        .get(reader, new Entry(field, parser));
038:            }
039:
040:            Cache longsCache = new Cache() {
041:
042:                protected Object createValue(IndexReader reader, Object entryKey)
043:                        throws IOException {
044:                    Entry entry = (Entry) entryKey;
045:                    String field = entry.field;
046:                    LongParser parser = (LongParser) entry.custom;
047:                    final long[] retArray = new long[reader.maxDoc()];
048:                    TermDocs termDocs = reader.termDocs();
049:                    TermEnum termEnum = reader.terms(new Term(field, ""));
050:                    try {
051:                        do {
052:                            Term term = termEnum.term();
053:                            if (term == null || term.field() != field)
054:                                break;
055:                            long termval = parser.parseLong(term.text());
056:                            termDocs.seek(termEnum);
057:                            while (termDocs.next()) {
058:                                retArray[termDocs.doc()] = termval;
059:                            }
060:                        } while (termEnum.next());
061:                    } finally {
062:                        termDocs.close();
063:                        termEnum.close();
064:                    }
065:                    return retArray;
066:                }
067:            };
068:
069:            // inherit javadocs
070:            public double[] getDoubles(IndexReader reader, String field)
071:                    throws IOException {
072:                return getDoubles(reader, field, DOUBLE_PARSER);
073:            }
074:
075:            // inherit javadocs
076:            public double[] getDoubles(IndexReader reader, String field,
077:                    DoubleParser parser) throws IOException {
078:                return (double[]) doublesCache.get(reader, new Entry(field,
079:                        parser));
080:            }
081:
082:            Cache doublesCache = new Cache() {
083:
084:                protected Object createValue(IndexReader reader, Object entryKey)
085:                        throws IOException {
086:                    Entry entry = (Entry) entryKey;
087:                    String field = entry.field;
088:                    DoubleParser parser = (DoubleParser) entry.custom;
089:                    final double[] retArray = new double[reader.maxDoc()];
090:                    TermDocs termDocs = reader.termDocs();
091:                    TermEnum termEnum = reader.terms(new Term(field, ""));
092:                    try {
093:                        do {
094:                            Term term = termEnum.term();
095:                            if (term == null || term.field() != field)
096:                                break;
097:                            double termval = parser.parseDouble(term.text());
098:                            termDocs.seek(termEnum);
099:                            while (termDocs.next()) {
100:                                retArray[termDocs.doc()] = termval;
101:                            }
102:                        } while (termEnum.next());
103:                    } finally {
104:                        termDocs.close();
105:                        termEnum.close();
106:                    }
107:                    return retArray;
108:                }
109:            };
110:
111:            // inherit javadocs
112:            public Object getAuto(IndexReader reader, String field)
113:                    throws IOException {
114:                return autoCache.get(reader, field);
115:            }
116:
117:            Cache autoCache = new Cache() {
118:
119:                protected Object createValue(IndexReader reader, Object fieldKey)
120:                        throws IOException {
121:                    String field = ((String) fieldKey).intern();
122:                    TermEnum enumerator = reader.terms(new Term(field, ""));
123:                    try {
124:                        Term term = enumerator.term();
125:                        if (term == null) {
126:                            throw new RuntimeException("no terms in field "
127:                                    + field + " - cannot determine sort type");
128:                        }
129:                        Object ret = null;
130:                        if (term.field() == field) {
131:                            String termtext = term.text().trim();
132:
133:                            /**
134:                             * Java 1.4 level code:
135:
136:                             if (pIntegers.matcher(termtext).matches())
137:                             return IntegerSortedHitQueue.comparator (reader, enumerator, field);
138:
139:                             else if (pFloats.matcher(termtext).matches())
140:                             return FloatSortedHitQueue.comparator (reader, enumerator, field);
141:                             */
142:
143:                            // Java 1.3 level code:
144:                            try {
145:                                Integer.parseInt(termtext);
146:                                ret = getInts(reader, field);
147:                            } catch (NumberFormatException nfe1) {
148:                                try {
149:                                    Long.parseLong(termtext);
150:                                    ret = getLongs(reader, field);
151:                                } catch (NumberFormatException nfe2) {
152:                                    try {
153:                                        Float.parseFloat(termtext);
154:                                        ret = getFloats(reader, field);
155:                                    } catch (NumberFormatException nfe3) {
156:                                        ret = getStringIndex(reader, field);
157:                                    }
158:                                }
159:                            }
160:                        } else {
161:                            throw new RuntimeException("field \"" + field
162:                                    + "\" does not appear to be indexed");
163:                        }
164:                        return ret;
165:                    } finally {
166:                        enumerator.close();
167:                    }
168:                }
169:            };
170:
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.