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


001:        package org.apache.lucene.search.spans;
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.analysis.standard.StandardAnalyzer;
023:        import org.apache.lucene.index.IndexReader;
024:        import org.apache.lucene.index.IndexWriter;
025:        import org.apache.lucene.index.Term;
026:        import org.apache.lucene.search.*;
027:
028:        /*******************************************************************************
029:         * Some expanded tests to make sure my patch doesn't break other SpanTermQuery
030:         * functionality.
031:         *
032:         * @author Reece Wilton
033:         */
034:        public class TestSpansAdvanced2 extends TestSpansAdvanced {
035:            IndexSearcher searcher2;
036:
037:            /**
038:             * Initializes the tests by adding documents to the index.
039:             */
040:            protected void setUp() throws Exception {
041:                super .setUp();
042:
043:                // create test index
044:                final IndexWriter writer = new IndexWriter(mDirectory,
045:                        new StandardAnalyzer(), false);
046:                addDocument(writer, "A", "Should we, could we, would we?");
047:                addDocument(writer, "B", "It should.  Should it?");
048:                addDocument(writer, "C", "It shouldn't.");
049:                addDocument(writer, "D", "Should we, should we, should we.");
050:                writer.close();
051:
052:                // re-open the searcher since we added more docs
053:                searcher2 = new IndexSearcher(mDirectory);
054:            }
055:
056:            /**
057:             * Verifies that the index has the correct number of documents.
058:             *
059:             * @throws Exception
060:             */
061:            public void testVerifyIndex() throws Exception {
062:                final IndexReader reader = IndexReader.open(mDirectory);
063:                assertEquals(8, reader.numDocs());
064:                reader.close();
065:            }
066:
067:            /**
068:             * Tests a single span query that matches multiple documents.
069:             *
070:             * @throws IOException
071:             */
072:            public void testSingleSpanQuery() throws IOException {
073:
074:                final Query spanQuery = new SpanTermQuery(new Term(FIELD_TEXT,
075:                        "should"));
076:                final String[] expectedIds = new String[] { "B", "D", "1", "2",
077:                        "3", "4", "A" };
078:                final float[] expectedScores = new float[] { 0.625f,
079:                        0.45927936f, 0.35355338f, 0.35355338f, 0.35355338f,
080:                        0.35355338f, 0.26516503f, };
081:                assertHits(searcher2, spanQuery, "single span query",
082:                        expectedIds, expectedScores);
083:            }
084:
085:            /**
086:             * Tests a single span query that matches multiple documents.
087:             *
088:             * @throws IOException
089:             */
090:            public void testMultipleDifferentSpanQueries() throws IOException {
091:
092:                final Query spanQuery1 = new SpanTermQuery(new Term(FIELD_TEXT,
093:                        "should"));
094:                final Query spanQuery2 = new SpanTermQuery(new Term(FIELD_TEXT,
095:                        "we"));
096:                final BooleanQuery query = new BooleanQuery();
097:                query.add(spanQuery1, BooleanClause.Occur.MUST);
098:                query.add(spanQuery2, BooleanClause.Occur.MUST);
099:                final String[] expectedIds = new String[] { "D", "A" };
100:                // these values were pre LUCENE-413
101:                // final float[] expectedScores = new float[] { 0.93163157f, 0.20698164f };
102:                final float[] expectedScores = new float[] { 1.0191123f,
103:                        0.93163157f };
104:                assertHits(searcher2, query, "multiple different span queries",
105:                        expectedIds, expectedScores);
106:            }
107:
108:            /**
109:             * Tests two span queries.
110:             *
111:             * @throws IOException
112:             */
113:            public void testBooleanQueryWithSpanQueries() throws IOException {
114:
115:                doTestBooleanQueryWithSpanQueries(searcher2, 0.73500174f);
116:            }
117:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.