Source Code Cross Referenced for TestMultiSearcherRanking.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.util.LuceneTestCase;
021:        import org.apache.lucene.analysis.standard.StandardAnalyzer;
022:        import org.apache.lucene.document.Document;
023:        import org.apache.lucene.document.Field;
024:        import org.apache.lucene.index.IndexWriter;
025:        import org.apache.lucene.queryParser.ParseException;
026:        import org.apache.lucene.queryParser.QueryParser;
027:        import org.apache.lucene.store.Directory;
028:        import org.apache.lucene.store.RAMDirectory;
029:
030:        import java.io.IOException;
031:
032:        /**
033:         * Tests {@link MultiSearcher} ranking, i.e. makes sure this bug is fixed:
034:         * http://issues.apache.org/bugzilla/show_bug.cgi?id=31841
035:         *
036:         * @version $Id: TestMultiSearcher.java 150492 2004-09-06 22:01:49Z dnaber $
037:         */
038:        public class TestMultiSearcherRanking extends LuceneTestCase {
039:
040:            private final boolean verbose = false; // set to true to output hits
041:            private final String FIELD_NAME = "body";
042:            private Searcher multiSearcher;
043:            private Searcher singleSearcher;
044:
045:            public void testOneTermQuery() throws IOException, ParseException {
046:                checkQuery("three");
047:            }
048:
049:            public void testTwoTermQuery() throws IOException, ParseException {
050:                checkQuery("three foo");
051:            }
052:
053:            public void testPrefixQuery() throws IOException, ParseException {
054:                checkQuery("multi*");
055:            }
056:
057:            public void testFuzzyQuery() throws IOException, ParseException {
058:                checkQuery("multiThree~");
059:            }
060:
061:            public void testRangeQuery() throws IOException, ParseException {
062:                checkQuery("{multiA TO multiP}");
063:            }
064:
065:            public void testMultiPhraseQuery() throws IOException,
066:                    ParseException {
067:                checkQuery("\"blueberry pi*\"");
068:            }
069:
070:            public void testNoMatchQuery() throws IOException, ParseException {
071:                checkQuery("+three +nomatch");
072:            }
073:
074:            /*
075:            public void testTermRepeatedQuery() throws IOException, ParseException {
076:              // TODO: this corner case yields different results.
077:              checkQuery("multi* multi* foo");
078:            }
079:             */
080:
081:            /**
082:             * checks if a query yields the same result when executed on
083:             * a single IndexSearcher containing all documents and on a
084:             * MultiSearcher aggregating sub-searchers
085:             * @param queryStr  the query to check.
086:             * @throws IOException
087:             * @throws ParseException
088:             */
089:            private void checkQuery(String queryStr) throws IOException,
090:                    ParseException {
091:                // check result hit ranking
092:                if (verbose)
093:                    System.out.println("Query: " + queryStr);
094:                QueryParser queryParser = new QueryParser(FIELD_NAME,
095:                        new StandardAnalyzer());
096:                Query query = queryParser.parse(queryStr);
097:                Hits multiSearcherHits = multiSearcher.search(query);
098:                Hits singleSearcherHits = singleSearcher.search(query);
099:                assertEquals(multiSearcherHits.length(), singleSearcherHits
100:                        .length());
101:                for (int i = 0; i < multiSearcherHits.length(); i++) {
102:                    Document docMulti = multiSearcherHits.doc(i);
103:                    Document docSingle = singleSearcherHits.doc(i);
104:                    if (verbose)
105:                        System.out.println("Multi:  "
106:                                + docMulti.get(FIELD_NAME) + " score="
107:                                + multiSearcherHits.score(i));
108:                    if (verbose)
109:                        System.out.println("Single: "
110:                                + docSingle.get(FIELD_NAME) + " score="
111:                                + singleSearcherHits.score(i));
112:                    assertEquals(multiSearcherHits.score(i), singleSearcherHits
113:                            .score(i), 0.001f);
114:                    assertEquals(docMulti.get(FIELD_NAME), docSingle
115:                            .get(FIELD_NAME));
116:                }
117:                if (verbose)
118:                    System.out.println();
119:            }
120:
121:            /**
122:             * initializes multiSearcher and singleSearcher with the same document set
123:             */
124:            protected void setUp() throws Exception {
125:                super .setUp();
126:                // create MultiSearcher from two seperate searchers
127:                Directory d1 = new RAMDirectory();
128:                IndexWriter iw1 = new IndexWriter(d1, new StandardAnalyzer(),
129:                        true);
130:                addCollection1(iw1);
131:                iw1.close();
132:                Directory d2 = new RAMDirectory();
133:                IndexWriter iw2 = new IndexWriter(d2, new StandardAnalyzer(),
134:                        true);
135:                addCollection2(iw2);
136:                iw2.close();
137:
138:                Searchable[] s = new Searchable[2];
139:                s[0] = new IndexSearcher(d1);
140:                s[1] = new IndexSearcher(d2);
141:                multiSearcher = new MultiSearcher(s);
142:
143:                // create IndexSearcher which contains all documents
144:                Directory d = new RAMDirectory();
145:                IndexWriter iw = new IndexWriter(d, new StandardAnalyzer(),
146:                        true);
147:                addCollection1(iw);
148:                addCollection2(iw);
149:                iw.close();
150:                singleSearcher = new IndexSearcher(d);
151:            }
152:
153:            private void addCollection1(IndexWriter iw) throws IOException {
154:                add("one blah three", iw);
155:                add("one foo three multiOne", iw);
156:                add("one foobar three multiThree", iw);
157:                add("blueberry pie", iw);
158:                add("blueberry strudel", iw);
159:                add("blueberry pizza", iw);
160:            }
161:
162:            private void addCollection2(IndexWriter iw) throws IOException {
163:                add("two blah three", iw);
164:                add("two foo xxx multiTwo", iw);
165:                add("two foobar xxx multiThreee", iw);
166:                add("blueberry chewing gum", iw);
167:                add("bluebird pizza", iw);
168:                add("bluebird foobar pizza", iw);
169:                add("piccadilly circus", iw);
170:            }
171:
172:            private void add(String value, IndexWriter iw) throws IOException {
173:                Document d = new Document();
174:                d.add(new Field(FIELD_NAME, value, Field.Store.YES,
175:                        Field.Index.TOKENIZED));
176:                iw.addDocument(d);
177:            }
178:
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.