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


001:        package org.apache.lucene.benchmark.byTask.feeds;
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.index.Term;
022:        import org.apache.lucene.queryParser.QueryParser;
023:        import org.apache.lucene.search.Query;
024:        import org.apache.lucene.search.WildcardQuery;
025:        import org.apache.lucene.search.spans.SpanFirstQuery;
026:        import org.apache.lucene.search.spans.SpanNearQuery;
027:        import org.apache.lucene.search.spans.SpanQuery;
028:        import org.apache.lucene.search.spans.SpanTermQuery;
029:
030:        import java.util.ArrayList;
031:        import java.util.Arrays;
032:        import java.util.List;
033:
034:        /**
035:         * A QueryMaker that makes queries devised manually (by Grant Ingersoll) for
036:         * searching in the Reuters collection.
037:         */
038:        public class ReutersQueryMaker extends AbstractQueryMaker implements 
039:                QueryMaker {
040:
041:            private static String[] STANDARD_QUERIES = {
042:                    //Start with some short queries
043:                    "Salomon",
044:                    "Comex",
045:                    "night trading",
046:                    "Japan Sony",
047:                    //Try some Phrase Queries
048:                    "\"Sony Japan\"",
049:                    "\"food needs\"~3",
050:                    "\"World Bank\"^2 AND Nigeria",
051:                    "\"World Bank\" -Nigeria",
052:                    "\"Ford Credit\"~5",
053:                    //Try some longer queries
054:                    "airline Europe Canada destination",
055:                    "Long term pressure by trade "
056:                            + "ministers is necessary if the current Uruguay round of talks on "
057:                            + "the General Agreement on Trade and Tariffs (GATT) is to "
058:                            + "succeed" };
059:
060:            private static Query[] getPrebuiltQueries(String field) {
061:                //  be wary of unanalyzed text
062:                return new Query[] {
063:                        new SpanFirstQuery(new SpanTermQuery(new Term(field,
064:                                "ford")), 5),
065:                        new SpanNearQuery(
066:                                new SpanQuery[] {
067:                                        new SpanTermQuery(new Term(field,
068:                                                "night")),
069:                                        new SpanTermQuery(new Term(field,
070:                                                "trading")) }, 4, false),
071:                        new SpanNearQuery(new SpanQuery[] {
072:                                new SpanFirstQuery(new SpanTermQuery(new Term(
073:                                        field, "ford")), 10),
074:                                new SpanTermQuery(new Term(field, "credit")) },
075:                                10, false),
076:                        new WildcardQuery(new Term(field, "fo*")), };
077:            }
078:
079:            /**
080:             * Parse the strings containing Lucene queries.
081:             *
082:             * @param qs array of strings containing query expressions
083:             * @param a  analyzer to use when parsing queries
084:             * @return array of Lucene queries
085:             */
086:            private static Query[] createQueries(List qs, Analyzer a) {
087:                QueryParser qp = new QueryParser(BasicDocMaker.BODY_FIELD, a);
088:                List queries = new ArrayList();
089:                for (int i = 0; i < qs.size(); i++) {
090:                    try {
091:
092:                        Object query = qs.get(i);
093:                        Query q = null;
094:                        if (query instanceof  String) {
095:                            q = qp.parse((String) query);
096:
097:                        } else if (query instanceof  Query) {
098:                            q = (Query) query;
099:
100:                        } else {
101:                            System.err.println("Unsupported Query Type: "
102:                                    + query);
103:                        }
104:
105:                        if (q != null) {
106:                            queries.add(q);
107:                        }
108:
109:                    } catch (Exception e) {
110:                        e.printStackTrace();
111:                    }
112:                }
113:
114:                return (Query[]) queries.toArray(new Query[0]);
115:            }
116:
117:            protected Query[] prepareQueries() throws Exception {
118:                // analyzer (default is standard analyzer)
119:                Analyzer anlzr = (Analyzer) Class
120:                        .forName(
121:                                config
122:                                        .get("analyzer",
123:                                                "org.apache.lucene.analysis.standard.StandardAnalyzer"))
124:                        .newInstance();
125:
126:                List queryList = new ArrayList(20);
127:                queryList.addAll(Arrays.asList(STANDARD_QUERIES));
128:                queryList.addAll(Arrays
129:                        .asList(getPrebuiltQueries(BasicDocMaker.BODY_FIELD)));
130:                return createQueries(queryList, anlzr);
131:            }
132:
133:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.