Source Code Cross Referenced for GoogleResultSet.java in  » Portal » Open-Portal » com » sun » portal » search » db » 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 » Portal » Open Portal » com.sun.portal.search.db 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:
006:        package com.sun.portal.search.db;
007:
008:        import com.sun.portal.search.rdm.*;
009:        import com.sun.portal.search.soif.*;
010:        import com.sun.portal.search.util.*;
011:
012:        import com.google.soap.search.*;
013:
014:        import java.util.*;
015:
016:        /**
017:         *
018:         * Google search result set implementation using RDMResultSet
019:         *
020:         */
021:        public class GoogleResultSet extends RDMResultSet {
022:
023:            /**
024:             * Creates a new instance of GoogleResultSet
025:             */
026:            GoogleResultSet(SToken st, RDMDb database, String query,
027:                    RDMTransaction t) {
028:                super (st, database, query, t);
029:            }
030:
031:            /**
032:             * Prepare Google Search Results
033:             */
034:            void setGoogleSearchResult(GoogleSearchResult gsr) {
035:                this .gsr = gsr;
036:                startHit = gsr.getStartIndex();
037:                endHit = gsr.getEndIndex();
038:                hitCount = gsr.getEstimatedTotalResultsCount();
039:                resultCount = endHit - startHit + 1;
040:                docCount = 2000000000;
041:            }
042:
043:            /**
044:             * Add view to RDMResultSet
045:             */
046:            void setView(Set view) {
047:                this .view = view;
048:            }
049:
050:            /**
051:             * Default view attribute set
052:             */
053:            static Set defaultView = new HashSet();
054:            static {
055:                defaultView.add("title");
056:                defaultView.add("description");
057:                defaultView.add("content-length");
058:            }
059:
060:            static private void configureHighlighting() {
061:
062:                // set up default highlighting from search config file
063:                String p = SearchConfig.getValue(SearchConfig.HIGHLIGHTS);
064:                if (p != null)
065:                    highlightsEnabled = p.equalsIgnoreCase("true");
066:
067:                p = SearchConfig.getValue(SearchConfig.HIGHLIGHT_TAGS);
068:                if (p != null) {
069:                    String[] tags = String2Array.string2Array(p, ',');
070:                    if (tags != null && tags.length == 6)
071:                        defaultHighlightTags = tags;
072:                }
073:
074:                p = SearchConfig.getValue(SearchConfig.HIGHLIGHT_TAGS_FIELD);
075:                if (p != null) {
076:                    String[] tags = String2Array.string2Array(p, ',');
077:                    if (tags != null && tags.length == 6)
078:                        defaultFldHighlightTags = tags;
079:                }
080:
081:            }
082:
083:            private void hlinit(String[] hltags) {
084:
085:                if (!hlconfigured) {
086:                    synchronized (this .getClass()) {
087:                        configureHighlighting();
088:                        hlconfigured = true;
089:                    }
090:                }
091:
092:                if (hlinited)
093:                    return;
094:
095:                highlightTags = (String[]) defaultHighlightTags.clone();
096:                fldHighlightTags = (String[]) defaultFldHighlightTags.clone();
097:
098:                if (hltags != null && hltags.length >= 6)
099:                    System.arraycopy(hltags, 0, highlightTags, 0, 6);
100:                if (hltags != null && hltags.length == 12)
101:                    System.arraycopy(hltags, 6, fldHighlightTags, 0, 6);
102:                hlinited = true;
103:            }
104:
105:            /**
106:             * Retrieve Search Results
107:             * @param i Document index
108:             * @param view Attributes
109:             * @param hltags Highlight tags
110:             * @return a SOIF hit, highlighted and filtered by view
111:             */
112:            public SOIF getResult(int i, Set view, String[] hltags) {
113:                if (hits == null) {
114:                    hits = gsr.getResultElements();
115:                }
116:
117:                if (i >= hits.length) {
118:                    return null;
119:                    //return null when the document index requested is
120:                    //greater than the google result count
121:                    //A temporary solution to avoid ArrayIndexOutOfBound 
122:                    //for Google search returns only 10 documents per search. 
123:                }
124:
125:                GoogleSearchResultElement r = hits[i];
126:
127:                hlinit(hltags);
128:
129:                SOIF s = new SOIF("DOCUMENT", r.getURL());
130:
131:                // insert/map the attributes
132:                if (view == null)
133:                    view = this .view;
134:                if (view == null)
135:                    view = defaultView;
136:                if (view.contains("hl-description"))
137:                    s.insert("hl-description", convertHighlight(r.getSnippet(),
138:                            true));
139:                if (view.contains("description"))
140:                    s.insert("description", convertHighlight(r.getSnippet(),
141:                            false));
142:                if (view.contains("hl-title"))
143:                    s.insert("hl-title", convertFieldHighlight(r.getTitle(),
144:                            true));
145:                if (view.contains("title"))
146:                    s.insert("title",
147:                            convertFieldHighlight(r.getTitle(), false));
148:                if (view.contains("hl-url"))
149:                    s.insert("hl-url", r.getURL());
150:                if (view.contains("content-length"))
151:                    s.insert("content-length", r.getCachedSize());
152:                if (view.contains("score"))
153:                    s.insert("score", "100");
154:                return s;
155:
156:            }
157:
158:            /**
159:             * Get search hit count
160:             * @return total number of hits for this search
161:             */
162:            public long getHitCount() {
163:                return hitCount;
164:            }
165:
166:            /**
167:             * Get document count
168:             * @return number of docs searched
169:             */
170:            public long getDocCount() {
171:                return docCount;
172:            }
173:
174:            /**
175:             * Transform the result set to string
176:             * @return tring representation of this result set
177:             */
178:            public java.lang.String toString() {
179:                return super .toString();
180:            }
181:
182:            /**
183:             * Get search result count
184:             * @return current number of hits in this set
185:             */
186:            public int getResultCount() {
187:                return resultCount;
188:            }
189:
190:            /**
191:             * Convert google highlight to portal style highlight
192:             * @param s string with highlights to be converted
193:             * @param hl true convert highlights, false remove highlights
194:             * @return the highlight converted string
195:             */
196:            public String convertHighlight(String s, boolean hl) {
197:                if (highlightsEnabled && hl) {
198:                    // convert google highlights to RDM highlights
199:                    // treat each google hit as a passage - could do better...
200:                    String t1 = s.replaceAll("(?i)<B>\\.\\.\\.</B>", "...");
201:                    String t2 = t1.replaceAll("(?i)<B>", highlightTags[2]
202:                            + highlightTags[4]);
203:                    String t3 = t2.replaceAll("(?i)</B>", highlightTags[5]
204:                            + highlightTags[3]);
205:                    String t4 = t3.replaceAll("(?i)<BR>", "");
206:                    return t4;
207:                } else {
208:                    // strip google highlights
209:                    String t1 = s.replaceAll("(?i)<B>", "");
210:                    String t2 = t1.replaceAll("(?i)</B>", "");
211:                    String t3 = t2.replaceAll("(?i)<BR>", "");
212:                    return t3;
213:                }
214:            }
215:
216:            /**
217:             * Convert google highlight to portal style field highlight
218:             * @param s string with highlights to be converted
219:             * @param hl true convert highlights, false remove highlights
220:             * @return the highlight converted string
221:             */
222:            public String convertFieldHighlight(String s, boolean hl) {
223:                if (highlightsEnabled && hl) {
224:                    // convert google highlights to RDM highlights
225:                    String t1 = s.replaceAll("(?i)<B>\\.\\.\\.</B>", "...");
226:                    String t2 = t1.replaceAll("(?i)<B>", fldHighlightTags[4]);
227:                    String t3 = t2.replaceAll("(?i)</B>", fldHighlightTags[5]);
228:                    return t3;
229:                } else {
230:                    // strip google highlights
231:                    String t1 = s.replaceAll("(?i)<B>", "");
232:                    String t2 = t1.replaceAll("(?i)</B>", "");
233:                    return t2;
234:                }
235:            }
236:
237:            private GoogleSearchResult gsr;
238:            private GoogleSearchResultElement[] hits;
239:            int startHit;
240:            int endHit;
241:            long hitCount;
242:            long docCount;
243:            int resultCount;
244:            Set view;
245:            boolean hlinited = false;
246:            String[] highlightTags;
247:            String[] fldHighlightTags;
248:
249:            // highlighting configuration
250:            static boolean hlconfigured = false;
251:            static boolean highlightsEnabled = true;
252:            static String[] defaultHighlightTags = { "... ", " ...",
253:                    "<font color=bb0033>", "</font>", "<b>", "</b>" };
254:            static String[] defaultFldHighlightTags = { "", "", "", "", "<b>",
255:                    "</b>" };
256:
257:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.