Source Code Cross Referenced for TestRangeQuery.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 org.apache.lucene.analysis.WhitespaceAnalyzer;
021:        import org.apache.lucene.document.Document;
022:        import org.apache.lucene.document.Field;
023:        import org.apache.lucene.index.IndexWriter;
024:        import org.apache.lucene.index.Term;
025:        import org.apache.lucene.store.RAMDirectory;
026:
027:        import org.apache.lucene.util.LuceneTestCase;
028:        import java.io.IOException;
029:
030:        /**
031:         * @author goller
032:         */
033:        public class TestRangeQuery extends LuceneTestCase {
034:
035:            private int docCount = 0;
036:            private RAMDirectory dir;
037:
038:            public void setUp() throws Exception {
039:                super .setUp();
040:                dir = new RAMDirectory();
041:            }
042:
043:            public void testExclusive() throws Exception {
044:                Query query = new RangeQuery(new Term("content", "A"),
045:                        new Term("content", "C"), false);
046:                initializeIndex(new String[] { "A", "B", "C", "D" });
047:                IndexSearcher searcher = new IndexSearcher(dir);
048:                Hits hits = searcher.search(query);
049:                assertEquals("A,B,C,D, only B in range", 1, hits.length());
050:                searcher.close();
051:
052:                initializeIndex(new String[] { "A", "B", "D" });
053:                searcher = new IndexSearcher(dir);
054:                hits = searcher.search(query);
055:                assertEquals("A,B,D, only B in range", 1, hits.length());
056:                searcher.close();
057:
058:                addDoc("C");
059:                searcher = new IndexSearcher(dir);
060:                hits = searcher.search(query);
061:                assertEquals("C added, still only B in range", 1, hits.length());
062:                searcher.close();
063:            }
064:
065:            public void testInclusive() throws Exception {
066:                Query query = new RangeQuery(new Term("content", "A"),
067:                        new Term("content", "C"), true);
068:
069:                initializeIndex(new String[] { "A", "B", "C", "D" });
070:                IndexSearcher searcher = new IndexSearcher(dir);
071:                Hits hits = searcher.search(query);
072:                assertEquals("A,B,C,D - A,B,C in range", 3, hits.length());
073:                searcher.close();
074:
075:                initializeIndex(new String[] { "A", "B", "D" });
076:                searcher = new IndexSearcher(dir);
077:                hits = searcher.search(query);
078:                assertEquals("A,B,D - A and B in range", 2, hits.length());
079:                searcher.close();
080:
081:                addDoc("C");
082:                searcher = new IndexSearcher(dir);
083:                hits = searcher.search(query);
084:                assertEquals("C added - A, B, C in range", 3, hits.length());
085:                searcher.close();
086:            }
087:
088:            public void testEqualsHashcode() {
089:                Query query = new RangeQuery(new Term("content", "A"),
090:                        new Term("content", "C"), true);
091:                query.setBoost(1.0f);
092:                Query other = new RangeQuery(new Term("content", "A"),
093:                        new Term("content", "C"), true);
094:                other.setBoost(1.0f);
095:
096:                assertEquals("query equals itself is true", query, query);
097:                assertEquals("equivalent queries are equal", query, other);
098:                assertEquals(
099:                        "hashcode must return same value when equals is true",
100:                        query.hashCode(), other.hashCode());
101:
102:                other.setBoost(2.0f);
103:                assertFalse("Different boost queries are not equal", query
104:                        .equals(other));
105:
106:                other = new RangeQuery(new Term("notcontent", "A"), new Term(
107:                        "notcontent", "C"), true);
108:                assertFalse("Different fields are not equal", query
109:                        .equals(other));
110:
111:                other = new RangeQuery(new Term("content", "X"), new Term(
112:                        "content", "C"), true);
113:                assertFalse("Different lower terms are not equal", query
114:                        .equals(other));
115:
116:                other = new RangeQuery(new Term("content", "A"), new Term(
117:                        "content", "Z"), true);
118:                assertFalse("Different upper terms are not equal", query
119:                        .equals(other));
120:
121:                query = new RangeQuery(null, new Term("content", "C"), true);
122:                other = new RangeQuery(null, new Term("content", "C"), true);
123:                assertEquals(
124:                        "equivalent queries with null lowerterms are equal()",
125:                        query, other);
126:                assertEquals(
127:                        "hashcode must return same value when equals is true",
128:                        query.hashCode(), other.hashCode());
129:
130:                query = new RangeQuery(new Term("content", "C"), null, true);
131:                other = new RangeQuery(new Term("content", "C"), null, true);
132:                assertEquals(
133:                        "equivalent queries with null upperterms are equal()",
134:                        query, other);
135:                assertEquals("hashcode returns same value", query.hashCode(),
136:                        other.hashCode());
137:
138:                query = new RangeQuery(null, new Term("content", "C"), true);
139:                other = new RangeQuery(new Term("content", "C"), null, true);
140:                assertFalse(
141:                        "queries with different upper and lower terms are not equal",
142:                        query.equals(other));
143:
144:                query = new RangeQuery(new Term("content", "A"), new Term(
145:                        "content", "C"), false);
146:                other = new RangeQuery(new Term("content", "A"), new Term(
147:                        "content", "C"), true);
148:                assertFalse("queries with different inclusive are not equal",
149:                        query.equals(other));
150:            }
151:
152:            private void initializeIndex(String[] values) throws IOException {
153:                IndexWriter writer = new IndexWriter(dir,
154:                        new WhitespaceAnalyzer(), true);
155:                for (int i = 0; i < values.length; i++) {
156:                    insertDoc(writer, values[i]);
157:                }
158:                writer.close();
159:            }
160:
161:            private void addDoc(String content) throws IOException {
162:                IndexWriter writer = new IndexWriter(dir,
163:                        new WhitespaceAnalyzer(), false);
164:                insertDoc(writer, content);
165:                writer.close();
166:            }
167:
168:            private void insertDoc(IndexWriter writer, String content)
169:                    throws IOException {
170:                Document doc = new Document();
171:
172:                doc.add(new Field("id", "id" + docCount, Field.Store.YES,
173:                        Field.Index.UN_TOKENIZED));
174:                doc.add(new Field("content", content, Field.Store.NO,
175:                        Field.Index.TOKENIZED));
176:
177:                writer.addDocument(doc);
178:                docCount++;
179:            }
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.