KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > search > SearchQueryData


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.ui.internal.search;
12
13 import java.io.*;
14 import java.net.*;
15 import java.util.*;
16
17 import org.eclipse.help.internal.base.*;
18 import org.eclipse.help.internal.search.*;
19 import org.eclipse.help.internal.util.*;
20 import org.eclipse.ui.*;
21
22 /**
23  * Help Search Query Data.
24  */

25 public class SearchQueryData {
26     private SearchQuery searchQuery;
27     /**
28      * Default maximum number of hits that a search engine will search stop
29      */

30     private static int MAX_HITS = 500;
31     /**
32      * maximum number of hits that a search engine will search
33      */

34     private int maxHits;
35     /**
36      * Indicates whether scope is being used
37      */

38     private boolean bookFiltering;
39     private IWorkingSet[] workingSets;
40     /**
41      * Indicates whether activities are used for filtering or results
42      */

43     private boolean activityFiltering = true;
44
45     /**
46      * HelpSearchQuery constructor.
47      */

48     public SearchQueryData() {
49         searchQuery = new SearchQuery();
50         maxHits = MAX_HITS;
51
52         String JavaDoc workingSetName = HelpBasePlugin.getDefault()
53                 .getPluginPreferences().getString(BaseHelpSystem.WORKING_SET);
54         if (workingSetName == null || workingSetName.length() == 0) {
55             bookFiltering = false;
56             workingSets = new IWorkingSet[0];
57         } else {
58             // Assumption: we only remember one working set (no multi selection)
59
IWorkingSet iws = PlatformUI.getWorkbench().getWorkingSetManager()
60                     .getWorkingSet(workingSetName);
61             if (iws == null) {
62                 bookFiltering = false;
63                 workingSets = new IWorkingSet[0];
64             } else {
65                 bookFiltering = true;
66                 workingSets = new IWorkingSet[]{iws};
67             }
68         }
69     }
70     public ISearchQuery getSearchQuery() {
71         return searchQuery;
72     }
73     /**
74      * Returns the list of books to be included in search, or null (if
75      * bookFiltering is off).
76      */

77     public IWorkingSet[] getSelectedWorkingSets() {
78         if (bookFiltering) {
79             return workingSets;
80         }
81         return null;
82     }
83     /**
84      * Returns the locale in which the search will be performed.
85      */

86     public String JavaDoc getLocale() {
87         return searchQuery.getLocale();
88     }
89     /**
90      * Returns true if books filtering is enabled.
91      */

92     public boolean isBookFiltering() {
93         return bookFiltering;
94     }
95     /**
96      * Enables book filtering.
97      *
98      * @param enable
99      * true if book filtering is turned on
100      */

101     public void setBookFiltering(boolean enable) {
102         this.bookFiltering = enable;
103         if (enable && workingSets.length > 0) {
104             /*
105              * selectedBooks = new ArrayList(); IToc tocs[] =
106              * HelpSystem.getTocManager().getTocs(searchQuery.getLocale()); for
107              * (int i = 0; i < tocs.length; i++) selectedBooks.add(tocs[i]);
108              */

109         }
110     }
111
112     /**
113      * Sets the working sets to be included in search.
114      *
115      * @param workingSets
116      */

117     public void setSelectedWorkingSets(IWorkingSet[] workingSets) {
118         this.workingSets = workingSets;
119     }
120
121     /**
122      * Sets search to be performed on the fields only.
123      *
124      * @param fieldSearch
125      * true if field only search
126      */

127     public void setFieldsSearch(boolean fieldSearch) {
128         searchQuery.setFieldSearch(fieldSearch);
129     }
130     /**
131      * Sets the maxHits.
132      *
133      * @param maxHits
134      * The maxHits to set
135      */

136     public void setMaxHits(int maxHits) {
137         this.maxHits = maxHits;
138     }
139
140     public String JavaDoc toURLQuery() {
141         String JavaDoc q = "searchWord=" //$NON-NLS-1$
142
+ URLCoder.encode(searchQuery.getSearchWord()) + "&maxHits=" //$NON-NLS-1$
143
+ maxHits + "&lang=" //$NON-NLS-1$
144
+ (searchQuery.getLocale());
145         if (!searchQuery.getFieldNames().isEmpty())
146             for (Iterator iterator = searchQuery.getFieldNames().iterator(); iterator
147                     .hasNext();) {
148                 String JavaDoc field = (String JavaDoc) iterator.next();
149                 try {
150                     q += "&field=" + URLEncoder.encode(field, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
151
} catch (UnsupportedEncodingException uee) {
152                 }
153             }
154         if (searchQuery.isFieldSearch())
155             q += "&fieldSearch=true"; //$NON-NLS-1$
156
else
157             q += "&fieldSearch=false"; //$NON-NLS-1$
158
if (bookFiltering) {
159             for (int i = 0; i < workingSets.length; i++) {
160                 q += "&scope=" + URLCoder.encode(workingSets[i].getName()); //$NON-NLS-1$
161
}
162         }
163         return q;
164     }
165     /**
166      * Gets the searchWord
167      *
168      * @return Returns a String
169      */

170     public String JavaDoc getSearchWord() {
171         return searchQuery.getSearchWord();
172     }
173     /**
174      * Sets the searchWord
175      *
176      * @param searchWord
177      * The search word to set
178      */

179     public void setSearchWord(String JavaDoc searchWord) {
180         searchQuery.setSearchWord(searchWord);
181     }
182     /**
183      * Gets the maxHits.
184      *
185      * @return Returns a int
186      */

187     public int getMaxHits() {
188         return maxHits;
189     }
190     /**
191      * Sets whether results should be filtered by enabled activities
192      */

193     public void setActivityFiltering(boolean filter) {
194         activityFiltering = filter;
195     }
196     /**
197      * Gets the maxHits.
198      *
199      * @return Returns true if results should be filter by enabled activites
200      */

201     public boolean isActivityFiltering() {
202         return activityFiltering;
203     }
204
205 }
206
Popular Tags