Source Code Cross Referenced for TestRangeFilter.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:        /**
004:         * Licensed to the Apache Software Foundation (ASF) under one or more
005:         * contributor license agreements.  See the NOTICE file distributed with
006:         * this work for additional information regarding copyright ownership.
007:         * The ASF licenses this file to You under the Apache License, Version 2.0
008:         * (the "License"); you may not use this file except in compliance with
009:         * the License.  You may obtain a copy of the License at
010:         *
011:         *     http://www.apache.org/licenses/LICENSE-2.0
012:         *
013:         * Unless required by applicable law or agreed to in writing, software
014:         * distributed under the License is distributed on an "AS IS" BASIS,
015:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016:         * See the License for the specific language governing permissions and
017:         * limitations under the License.
018:         */
019:
020:        import java.io.IOException;
021:
022:        import org.apache.lucene.index.IndexReader;
023:        import org.apache.lucene.index.Term;
024:
025:        /**
026:         * A basic 'positive' Unit test class for the RangeFilter class.
027:         *
028:         * <p>
029:         * NOTE: at the moment, this class only tests for 'positive' results,
030:         * it does not verify the results to ensure there are no 'false positives',
031:         * nor does it adequately test 'negative' results.  It also does not test
032:         * that garbage in results in an Exception.
033:         */
034:        public class TestRangeFilter extends BaseTestRangeFilter {
035:
036:            public TestRangeFilter(String name) {
037:                super (name);
038:            }
039:
040:            public TestRangeFilter() {
041:                super ();
042:            }
043:
044:            public void testRangeFilterId() throws IOException {
045:
046:                IndexReader reader = IndexReader.open(index);
047:                IndexSearcher search = new IndexSearcher(reader);
048:
049:                int medId = ((maxId - minId) / 2);
050:
051:                String minIP = pad(minId);
052:                String maxIP = pad(maxId);
053:                String medIP = pad(medId);
054:
055:                int numDocs = reader.numDocs();
056:
057:                assertEquals("num of docs", numDocs, 1 + maxId - minId);
058:
059:                Hits result;
060:                Query q = new TermQuery(new Term("body", "body"));
061:
062:                // test id, bounded on both ends
063:
064:                result = search.search(q, new RangeFilter("id", minIP, maxIP,
065:                        T, T));
066:                assertEquals("find all", numDocs, result.length());
067:
068:                result = search.search(q, new RangeFilter("id", minIP, maxIP,
069:                        T, F));
070:                assertEquals("all but last", numDocs - 1, result.length());
071:
072:                result = search.search(q, new RangeFilter("id", minIP, maxIP,
073:                        F, T));
074:                assertEquals("all but first", numDocs - 1, result.length());
075:
076:                result = search.search(q, new RangeFilter("id", minIP, maxIP,
077:                        F, F));
078:                assertEquals("all but ends", numDocs - 2, result.length());
079:
080:                result = search.search(q, new RangeFilter("id", medIP, maxIP,
081:                        T, T));
082:                assertEquals("med and up", 1 + maxId - medId, result.length());
083:
084:                result = search.search(q, new RangeFilter("id", minIP, medIP,
085:                        T, T));
086:                assertEquals("up to med", 1 + medId - minId, result.length());
087:
088:                // unbounded id
089:
090:                result = search.search(q, new RangeFilter("id", minIP, null, T,
091:                        F));
092:                assertEquals("min and up", numDocs, result.length());
093:
094:                result = search.search(q, new RangeFilter("id", null, maxIP, F,
095:                        T));
096:                assertEquals("max and down", numDocs, result.length());
097:
098:                result = search.search(q, new RangeFilter("id", minIP, null, F,
099:                        F));
100:                assertEquals("not min, but up", numDocs - 1, result.length());
101:
102:                result = search.search(q, new RangeFilter("id", null, maxIP, F,
103:                        F));
104:                assertEquals("not max, but down", numDocs - 1, result.length());
105:
106:                result = search.search(q, new RangeFilter("id", medIP, maxIP,
107:                        T, F));
108:                assertEquals("med and up, not max", maxId - medId, result
109:                        .length());
110:
111:                result = search.search(q, new RangeFilter("id", minIP, medIP,
112:                        F, T));
113:                assertEquals("not min, up to med", medId - minId, result
114:                        .length());
115:
116:                // very small sets
117:
118:                result = search.search(q, new RangeFilter("id", minIP, minIP,
119:                        F, F));
120:                assertEquals("min,min,F,F", 0, result.length());
121:                result = search.search(q, new RangeFilter("id", medIP, medIP,
122:                        F, F));
123:                assertEquals("med,med,F,F", 0, result.length());
124:                result = search.search(q, new RangeFilter("id", maxIP, maxIP,
125:                        F, F));
126:                assertEquals("max,max,F,F", 0, result.length());
127:
128:                result = search.search(q, new RangeFilter("id", minIP, minIP,
129:                        T, T));
130:                assertEquals("min,min,T,T", 1, result.length());
131:                result = search.search(q, new RangeFilter("id", null, minIP, F,
132:                        T));
133:                assertEquals("nul,min,F,T", 1, result.length());
134:
135:                result = search.search(q, new RangeFilter("id", maxIP, maxIP,
136:                        T, T));
137:                assertEquals("max,max,T,T", 1, result.length());
138:                result = search.search(q, new RangeFilter("id", maxIP, null, T,
139:                        F));
140:                assertEquals("max,nul,T,T", 1, result.length());
141:
142:                result = search.search(q, new RangeFilter("id", medIP, medIP,
143:                        T, T));
144:                assertEquals("med,med,T,T", 1, result.length());
145:
146:            }
147:
148:            public void testRangeFilterRand() throws IOException {
149:
150:                IndexReader reader = IndexReader.open(index);
151:                IndexSearcher search = new IndexSearcher(reader);
152:
153:                String minRP = pad(minR);
154:                String maxRP = pad(maxR);
155:
156:                int numDocs = reader.numDocs();
157:
158:                assertEquals("num of docs", numDocs, 1 + maxId - minId);
159:
160:                Hits result;
161:                Query q = new TermQuery(new Term("body", "body"));
162:
163:                // test extremes, bounded on both ends
164:
165:                result = search.search(q, new RangeFilter("rand", minRP, maxRP,
166:                        T, T));
167:                assertEquals("find all", numDocs, result.length());
168:
169:                result = search.search(q, new RangeFilter("rand", minRP, maxRP,
170:                        T, F));
171:                assertEquals("all but biggest", numDocs - 1, result.length());
172:
173:                result = search.search(q, new RangeFilter("rand", minRP, maxRP,
174:                        F, T));
175:                assertEquals("all but smallest", numDocs - 1, result.length());
176:
177:                result = search.search(q, new RangeFilter("rand", minRP, maxRP,
178:                        F, F));
179:                assertEquals("all but extremes", numDocs - 2, result.length());
180:
181:                // unbounded
182:
183:                result = search.search(q, new RangeFilter("rand", minRP, null,
184:                        T, F));
185:                assertEquals("smallest and up", numDocs, result.length());
186:
187:                result = search.search(q, new RangeFilter("rand", null, maxRP,
188:                        F, T));
189:                assertEquals("biggest and down", numDocs, result.length());
190:
191:                result = search.search(q, new RangeFilter("rand", minRP, null,
192:                        F, F));
193:                assertEquals("not smallest, but up", numDocs - 1, result
194:                        .length());
195:
196:                result = search.search(q, new RangeFilter("rand", null, maxRP,
197:                        F, F));
198:                assertEquals("not biggest, but down", numDocs - 1, result
199:                        .length());
200:
201:                // very small sets
202:
203:                result = search.search(q, new RangeFilter("rand", minRP, minRP,
204:                        F, F));
205:                assertEquals("min,min,F,F", 0, result.length());
206:                result = search.search(q, new RangeFilter("rand", maxRP, maxRP,
207:                        F, F));
208:                assertEquals("max,max,F,F", 0, result.length());
209:
210:                result = search.search(q, new RangeFilter("rand", minRP, minRP,
211:                        T, T));
212:                assertEquals("min,min,T,T", 1, result.length());
213:                result = search.search(q, new RangeFilter("rand", null, minRP,
214:                        F, T));
215:                assertEquals("nul,min,F,T", 1, result.length());
216:
217:                result = search.search(q, new RangeFilter("rand", maxRP, maxRP,
218:                        T, T));
219:                assertEquals("max,max,T,T", 1, result.length());
220:                result = search.search(q, new RangeFilter("rand", maxRP, null,
221:                        T, F));
222:                assertEquals("max,nul,T,T", 1, result.length());
223:
224:            }
225:
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.