Source Code Cross Referenced for LuceneOrderBy.java in  » Content-Management-System » hippo » org » apache » slide » index » lucene » 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 » Content Management System » hippo » org.apache.slide.index.lucene 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header$
003:         * $Revision: 9073 $
004:         * $Date: 2007-11-22 09:04:41 -0800 $
005:         *
006:         * ====================================================================
007:         *
008:         * Copyright 1999-2002 The Apache Software Foundation 
009:         *
010:         * Licensed under the Apache License, Version 2.0 (the "License");
011:         * you may not use this file except in compliance with the License.
012:         * You may obtain a copy of the License at
013:         *
014:         *     http://www.apache.org/licenses/LICENSE-2.0
015:         *
016:         * Unless required by applicable law or agreed to in writing, software
017:         * distributed under the License is distributed on an "AS IS" BASIS,
018:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019:         * See the License for the specific language governing permissions and
020:         * limitations under the License.
021:         *
022:         */
023:
024:        package org.apache.slide.index.lucene;
025:
026:        import java.util.Iterator;
027:        import java.util.List;
028:
029:        import org.apache.lucene.search.Sort;
030:        import org.apache.lucene.search.SortField;
031:        import org.apache.slide.common.PropertyName;
032:        import org.apache.slide.search.InvalidQueryException;
033:        import org.apache.slide.search.basic.Literals;
034:        import org.apache.slide.search.basic.OrderBy;
035:        import org.jdom.Attribute;
036:        import org.jdom.Element;
037:        import org.jdom.Namespace;
038:
039:        /**
040:         * Encapsulate an OrderBy expression. Also supplies a Comparator according
041:         * to the specified parameters in the OrderBy expression,
042:         *
043:         * @version $Revision: 9073 $
044:         */
045:        public class LuceneOrderBy extends OrderBy {
046:
047:            private Sort theSorter = null;
048:
049:            //private Index index = null;
050:
051:            public LuceneOrderBy() {
052:                super ();
053:                //this.index = index;
054:            }
055:
056:            /**
057:             * initializes an OrderBy.
058:             *
059:             * @param orderByElement  the JDOM element containing the
060:             *        orderBy expression
061:             */
062:            public void init(Element orderByElement)
063:                    throws InvalidQueryException {
064:
065:                super .init(orderByElement);
066:                orderByElements.clear();
067:
068:                Namespace nameSpace = orderByElement.getNamespace();
069:                Iterator it = orderByElement.getChildren(Literals.ORDER,
070:                        nameSpace).iterator();
071:
072:                while (it.hasNext()) {
073:                    Element order = (Element) it.next();
074:                    PropertyName p = getProperty(order);
075:                    boolean isAscending = isAscending(order);
076:
077:                    // WE DON'T SUPPORT CASE SENSITIVITY PER REQUEST/ORDER BY
078:                    if (p.getName().equals("score")
079:                            && p.getNamespace().equals("DAV:")) {
080:                        orderByElements.add(SortField.FIELD_SCORE);
081:                    } else {
082:                        orderByElements.add(new SortField(IndexConfiguration
083:                                .generateFieldName(p.getNamespace(), p
084:                                        .getName()), SortField.STRING,
085:                                !isAscending));
086:                    }
087:
088:                }
089:                if (orderByElements.size() > 0)
090:                    theSorter = new Sort((SortField[]) orderByElements
091:                            .toArray(new SortField[0]));
092:            }
093:
094:            public Sort getSorter() {
095:                return theSorter;
096:            }
097:
098:            /**
099:             * Method isCaseSensitive
100:             *
101:             * @param    order               an order Element
102:             *
103:             * @return   true if this order element shall regard case
104:             *
105:             */
106:            private boolean isCaseSensitive(Element order) {
107:                boolean result = true;
108:                Attribute caseSens = order.getAttribute(Literals.CASESENSITIVE,
109:                        order.getNamespace());
110:
111:                if (caseSens != null) {
112:                    try {
113:                        result = caseSens.getBooleanValue();
114:                    } catch (org.jdom.DataConversionException e) {
115:                        e.printStackTrace();
116:                    }
117:                }
118:                return result;
119:            }
120:
121:            /**
122:             * Method isAscending
123:             *
124:             * @param    order               an Element
125:             *
126:             * @return   a boolean
127:             *
128:             * @throws   InvalidQueryException if ascending and descending is supplied
129:             *
130:             */
131:            private boolean isAscending(Element order)
132:                    throws InvalidQueryException {
133:                Element asc = order.getChild(Literals.ASCENDING, order
134:                        .getNamespace());
135:                Element desc = order.getChild(Literals.DESCENDING, order
136:                        .getNamespace());
137:                boolean result = true;
138:
139:                if (asc != null && desc != null)
140:                    throw new InvalidQueryException(
141:                            "either ascending or descending may be supplied");
142:
143:                if (desc != null)
144:                    result = false;
145:
146:                return result;
147:            }
148:
149:            /**
150:             * Method getPropName
151:             *
152:             * @param    order               an Element
153:             *
154:             * @return   a String
155:             *
156:             * @throws   InvalidQueryException
157:             *
158:             */
159:            private PropertyName getProperty(Element orderElem)
160:                    throws InvalidQueryException {
161:
162:                List propList = orderElem.getChild(Literals.PROP,
163:                        orderElem.getNamespace()).getChildren();
164:
165:                if (propList.size() != 1)
166:                    throw new InvalidQueryException(
167:                            "Expected exactly 1 prop element, found "
168:                                    + propList.size());
169:
170:                Element propElem = (Element) propList.get(0);
171:
172:                return createProperty(propElem);
173:            }
174:
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.