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


001:        package org.apache.lucene.search.function;
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.Analyzer;
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.document.Fieldable;
025:        import org.apache.lucene.index.IndexWriter;
026:        import org.apache.lucene.store.Directory;
027:        import org.apache.lucene.store.RAMDirectory;
028:
029:        import org.apache.lucene.util.LuceneTestCase;
030:
031:        /**
032:         * Setup for function tests
033:         */
034:        public abstract class FunctionTestSetup extends LuceneTestCase {
035:
036:            /**
037:             * Actual score computation order is slightly different than assumptios
038:             * this allows for a small amount of variation
039:             */
040:            public static float TEST_SCORE_TOLERANCE_DELTA = 0.001f;
041:
042:            protected static final boolean DBG = false; // change to true for logging to print
043:
044:            protected static final int N_DOCS = 17; // select a primary number > 2
045:
046:            protected static final String ID_FIELD = "id";
047:            protected static final String TEXT_FIELD = "text";
048:            protected static final String INT_FIELD = "iii";
049:            protected static final String FLOAT_FIELD = "fff";
050:
051:            private static final String DOC_TEXT_LINES[] = {
052:                    "Well, this is just some plain text we use for creating the ",
053:                    "test documents. It used to be a text from an online collection ",
054:                    "devoted to first aid, but if there was there an (online) lawyers ",
055:                    "first aid collection with legal advices, \"it\" might have quite ",
056:                    "probably advised one not to include \"it\"'s text or the text of ",
057:                    "any other online collection in one's code, unless one has money ",
058:                    "that one don't need and one is happy to donate for lawyers ",
059:                    "charity. Anyhow at some point, rechecking the usage of this text, ",
060:                    "it became uncertain that this text is free to use, because ",
061:                    "the web site in the disclaimer of he eBook containing that text ",
062:                    "was not responding anymore, and at the same time, in projGut, ",
063:                    "searching for first aid no longer found that eBook as well. ",
064:                    "So here we are, with a perhaps much less interesting ",
065:                    "text for the test, but oh much much safer. ", };
066:
067:            protected Directory dir;
068:            protected Analyzer anlzr;
069:
070:            /* @override constructor */
071:            public FunctionTestSetup(String name) {
072:                super (name);
073:            }
074:
075:            /* @override */
076:            protected void tearDown() throws Exception {
077:                super .tearDown();
078:                super .tearDown();
079:                dir = null;
080:                anlzr = null;
081:            }
082:
083:            /* @override */
084:            protected void setUp() throws Exception {
085:                super .setUp();
086:                // prepare a small index with just a few documents.  
087:                super .setUp();
088:                dir = new RAMDirectory();
089:                anlzr = new StandardAnalyzer();
090:                IndexWriter iw = new IndexWriter(dir, anlzr);
091:                // add docs not exactly in natural ID order, to verify we do check the order of docs by scores
092:                int remaining = N_DOCS;
093:                boolean done[] = new boolean[N_DOCS];
094:                int i = 0;
095:                while (remaining > 0) {
096:                    if (done[i]) {
097:                        throw new Exception(
098:                                "to set this test correctly N_DOCS="
099:                                        + N_DOCS
100:                                        + " must be primary and greater than 2!");
101:                    }
102:                    addDoc(iw, i);
103:                    done[i] = true;
104:                    i = (i + 4) % N_DOCS;
105:                    remaining--;
106:                }
107:                iw.close();
108:            }
109:
110:            private void addDoc(IndexWriter iw, int i) throws Exception {
111:                Document d = new Document();
112:                Fieldable f;
113:                int scoreAndID = i + 1;
114:
115:                f = new Field(ID_FIELD, id2String(scoreAndID), Field.Store.YES,
116:                        Field.Index.UN_TOKENIZED); // for debug purposes
117:                f.setOmitNorms(true);
118:                d.add(f);
119:
120:                f = new Field(TEXT_FIELD, "text of doc" + scoreAndID
121:                        + textLine(i), Field.Store.NO, Field.Index.TOKENIZED); // for regular search
122:                f.setOmitNorms(true);
123:                d.add(f);
124:
125:                f = new Field(INT_FIELD, "" + scoreAndID, Field.Store.NO,
126:                        Field.Index.UN_TOKENIZED); // for function scoring
127:                f.setOmitNorms(true);
128:                d.add(f);
129:
130:                f = new Field(FLOAT_FIELD, scoreAndID + ".000", Field.Store.NO,
131:                        Field.Index.UN_TOKENIZED); // for function scoring
132:                f.setOmitNorms(true);
133:                d.add(f);
134:
135:                iw.addDocument(d);
136:                log("added: " + d);
137:            }
138:
139:            // 17 --> ID00017
140:            protected String id2String(int scoreAndID) {
141:                String s = "000000000" + scoreAndID;
142:                int n = ("" + N_DOCS).length() + 3;
143:                int k = s.length() - n;
144:                return "ID" + s.substring(k);
145:            }
146:
147:            // some text line for regular search
148:            private String textLine(int docNum) {
149:                return DOC_TEXT_LINES[docNum % DOC_TEXT_LINES.length];
150:            }
151:
152:            // extract expected doc score from its ID Field: "ID7" --> 7.0
153:            protected float expectedFieldScore(String docIDFieldVal) {
154:                return Float.parseFloat(docIDFieldVal.substring(2));
155:            }
156:
157:            // debug messages (change DBG to true for anything to print) 
158:            protected void log(Object o) {
159:                if (DBG) {
160:                    System.out.println(o.toString());
161:                }
162:            }
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.