KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > search > CmsSearchParameters


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/search/CmsSearchParameters.java,v $
3  * Date : $Date: 2006/04/28 15:20:52 $
4  * Version: $Revision: 1.8 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.search;
33
34 import org.opencms.main.CmsException;
35 import org.opencms.main.CmsIllegalArgumentException;
36 import org.opencms.main.CmsLog;
37 import org.opencms.main.OpenCms;
38 import org.opencms.search.documents.I_CmsDocumentFactory;
39 import org.opencms.util.CmsStringUtil;
40
41 import java.util.ArrayList JavaDoc;
42 import java.util.Iterator JavaDoc;
43 import java.util.LinkedList JavaDoc;
44 import java.util.List JavaDoc;
45
46 import org.apache.commons.collections.ListUtils;
47 import org.apache.commons.logging.Log;
48 import org.apache.lucene.search.Sort;
49 import org.apache.lucene.search.SortField;
50
51 /**
52  * Contains the search parameters for a call to <code>{@link org.opencms.search.CmsSearchIndex#search(org.opencms.file.CmsObject, CmsSearchParameters, int)}</code>.<p>
53  *
54  * Primary purpose is translation of search arguments to response parameters and from request parameters as
55  * well as support for creation of restrictions of several search query parameter sets. <p>
56  *
57  *
58  * @version $Revision: 1.8 $
59  *
60  * @author Alexander Kandzior
61  *
62  * @version $Revision: 1.8 $
63  *
64  * @since 6.0.0
65  */

66 public class CmsSearchParameters {
67
68     /** Sort result documents by date of creation, then score. */
69     public static final Sort SORT_DATE_CREATED = new Sort(new SortField[] {
70         new SortField(I_CmsDocumentFactory.DOC_DATE_CREATED, SortField.STRING, true),
71         SortField.FIELD_SCORE});
72
73     /** Sort result documents by date of last modification, then score. */
74     public static final Sort SORT_DATE_LASTMODIFIED = new Sort(new SortField[] {
75         new SortField(I_CmsDocumentFactory.DOC_DATE_LASTMODIFIED, SortField.STRING, true),
76         SortField.FIELD_SCORE});
77
78     /** Default sort order (by document score - for this <code>null</code> gave best performance). */
79     public static final Sort SORT_DEFAULT = null;
80
81     /** Names of the default sort options. */
82     public static final String JavaDoc[] SORT_NAMES = {
83         "SORT_DEFAULT",
84         "SORT_DATE_CREATED",
85         "SORT_DATE_LASTMODIFIED",
86         "SORT_TITLE"};
87
88     /** Sort result documents by title, then score. */
89     public static final Sort SORT_TITLE = new Sort(new SortField[] {
90         new SortField(I_CmsDocumentFactory.DOC_TITLE_KEY),
91         SortField.FIELD_SCORE});
92
93     /** The log object for this class. */
94     private static final Log LOG = CmsLog.getLog(CmsSearchParameters.class);
95
96     /** The index to search. */
97     protected CmsSearchIndex m_index;
98
99     /** The current result page. */
100     protected int m_page;
101
102     /** The minimum length of the search query. */
103     protected int m_queryLength;
104
105     /** If <code>true</code>, the category count is calculated for all search results. */
106     private boolean m_calculateCategories;
107
108     /** The list of categories to limit the search to. */
109     private List JavaDoc m_categories;
110
111     /** The list of search index fields to search in. */
112     private List JavaDoc m_fields;
113
114     /** The search query to use. */
115     private String JavaDoc m_query;
116
117     /** Only resource that are sub-resource of one of the search roots are included in the search result. */
118     private List JavaDoc m_roots;
119
120     /** The sort order for the search. */
121     private Sort m_sort;
122
123     /**
124      * Creates a new search parameter instance with no search query and
125      * default values for the remaining parameters. <p>
126      *
127      * Before using this search parameters for a search method
128      * <code>{@link #setQuery(String)}</code> has to be invoked. <p>
129      *
130      */

131     public CmsSearchParameters() {
132
133         this("");
134     }
135
136     /**
137      * Creates a new search parameter instance with the provided search query and
138      * default values for the remaining parameters. <p>
139      *
140      * Only the "meta" field (combination of content and title) will be used for search.
141      * No search root restriction is chosen.
142      * No category restriction is used.
143      * No categorie counts are calculated for the result.
144      * Sorting is turned off. This is a simple but fast setup. <p>
145      *
146      * @param query the query to search for
147      */

148     public CmsSearchParameters(String JavaDoc query) {
149
150         this(query, null, null, null, false, null);
151
152     }
153
154     /**
155      * Creates a new search parameter instance with the provided parameter values.<p>
156      *
157      * @param query the search term to search the index
158      * @param fields the list of fields to search
159      * @param roots only resource that are sub-resource of one of the search roots are included in the search result
160      * @param categories the list of categories to limit the search to
161      * @param calculateCategories if <code>true</code>, the category count is calculated for all search results
162      * (use with caution, this option uses much performance)
163      * @param sort the sort order for the search
164      */

165     public CmsSearchParameters(
166         String JavaDoc query,
167         List JavaDoc fields,
168         List JavaDoc roots,
169         List JavaDoc categories,
170         boolean calculateCategories,
171         Sort sort) {
172
173         super();
174         m_query = (query == null) ? "" : query;
175         if (fields == null) {
176             fields = new ArrayList JavaDoc(2);
177             fields.add(CmsSearchIndex.DOC_META_FIELDS[0]);
178             fields.add(CmsSearchIndex.DOC_META_FIELDS[1]);
179         }
180         m_fields = fields;
181         if (roots == null) {
182             roots = new ArrayList JavaDoc();
183         }
184         m_roots = roots;
185         m_categories = (categories == null) ? new LinkedList JavaDoc() : categories;
186         m_calculateCategories = calculateCategories;
187         // null sort is allowed default
188
m_sort = sort;
189         m_page = 1;
190         m_queryLength = -1;
191     }
192
193     /**
194      * Returns wether category counts are calculated for search results or not. <p>
195      *
196      * @return a boolean that tells wether category counts are calculated for search results or not
197      */

198     public boolean getCalculateCategories() {
199
200         return m_calculateCategories;
201     }
202
203     /**
204      * Returns the list of categories to limit the search to.<p>
205      *
206      * @return the list of categories to limit the search to
207      */

208     public List JavaDoc getCategories() {
209
210         return m_categories;
211     }
212
213     /**
214      * Returns the list of search index fields to search in.<p>
215      *
216      * @return the list of search index fields to search in
217      */

218     public List JavaDoc getFields() {
219
220         return m_fields;
221     }
222
223     /**
224      * Get the name of the index for the search.<p>
225      *
226      * @return the name of the index for the search
227      */

228     public String JavaDoc getIndex() {
229
230         return m_index.getName();
231     }
232
233     /**
234      * Returns the search query to use.<p>
235      *
236      * @return the search query to use
237      */

238     public String JavaDoc getQuery() {
239
240         return m_query;
241     }
242
243     /**
244      * Gets the minimum search query length.<p>
245      *
246      * @return the minimum search query length
247      */

248     public int getQueryLength() {
249
250         return m_queryLength;
251     }
252
253     /**
254      * Returns the list of strings of search roots to use.<p>
255      *
256      * Only resource that are sub-resource of one of the search roots are included in the search result.<p>
257      *
258      * @return the list of strings of search roots to use
259      */

260     public List JavaDoc getRoots() {
261
262         return m_roots;
263     }
264
265     /**
266      * Returns the list of categories to limit the search to.<p>
267      *
268      * @return the list of categories to limit the search to
269      */

270     public String JavaDoc getSearchCategories() {
271
272         return toSeparatedString(getCategories(), ',');
273     }
274
275     /**
276      * Returns wether the content field will be searched or not.
277      *
278      * @return wether the content field will be searched or not
279      *
280      * @see I_CmsDocumentFactory#DOC_CONTENT
281      */

282     public boolean getSearchFieldContent() {
283
284         return m_fields.contains(I_CmsDocumentFactory.DOC_CONTENT);
285     }
286
287     /**
288      * Returns wether the description field will be searched or not.
289      *
290      * @return wether the description field will be searched or not
291      *
292      * @see I_CmsDocumentFactory#DOC_DESCRIPTION
293      */

294     public boolean getSearchFieldDescription() {
295
296         return m_fields.contains(I_CmsDocumentFactory.DOC_DESCRIPTION);
297     }
298
299     /**
300      * Returns wether the keywords field will be searched or not.
301      *
302      * @return wether the keywords field will be searched or not
303      *
304      * @see I_CmsDocumentFactory#DOC_KEYWORDS
305      */

306     public boolean getSearchFieldKeywords() {
307
308         return m_fields.contains(I_CmsDocumentFactory.DOC_KEYWORDS);
309     }
310
311     /**
312      * Returns wether the meta field will be searched or not.
313      *
314      * @return wether the meta field will be searched or not
315      *
316      * @see I_CmsDocumentFactory#DOC_META
317      */

318     public boolean getSearchFieldMeta() {
319
320         return m_fields.contains(I_CmsDocumentFactory.DOC_META);
321     }
322
323     /**
324      * Returns wether the title field will be searched or not.
325      *
326      * @return wether the title field will be searched or not
327      *
328      * @see I_CmsDocumentFactory#DOC_TITLE_INDEXED
329      */

330     public boolean getSearchFieldTitle() {
331
332         return m_fields.contains(I_CmsDocumentFactory.DOC_TITLE_INDEXED);
333     }
334
335     /**
336      * Returns the search index to search in or null if not set before
337      * (<code>{@link #setSearchIndex(CmsSearchIndex)}</code>). <p>
338      *
339      * @return the search index to search in or null if not set before (<code>{@link #setSearchIndex(CmsSearchIndex)}</code>)
340      */

341     public CmsSearchIndex getSearchIndex() {
342
343         return m_index;
344     }
345
346     /**
347      * Returns the search page to display.<p>
348      *
349      * @return the search page to display
350      */

351     public int getSearchPage() {
352
353         return m_page;
354     }
355
356     /**
357      * Returns the comma separated lists of root folder names to restrict search to.<p>
358      *
359      * This method is a "sibling" to method <code>{@link #getRoots()}</code> but with
360      * the support of being useable with widget technology. <p>
361      *
362      * @return the comma separated lists of field names to search in
363      *
364      * @see #setSortName(String)
365      */

366
367     public String JavaDoc getSearchRoots() {
368
369         return toSeparatedString(m_roots, ',');
370     }
371
372     /**
373      * Returns the instance that defines the sort order for the results.
374      *
375      * @return the instance that defines the sort order for the results
376      */

377     public Sort getSort() {
378
379         return m_sort;
380     }
381
382     /**
383      * Returns the name of the sort option being used.<p>
384      * @return the name of the sort option being used
385      *
386      * @see #SORT_NAMES
387      * @see #setSortName(String)
388      */

389     public String JavaDoc getSortName() {
390
391         if (m_sort == SORT_DATE_CREATED) {
392             return SORT_NAMES[1];
393         }
394         if (m_sort == SORT_DATE_LASTMODIFIED) {
395             return SORT_NAMES[2];
396         }
397         if (m_sort == SORT_TITLE) {
398             return SORT_NAMES[3];
399         }
400         return SORT_NAMES[0];
401     }
402
403     /**
404      * Returns <code>true</code> if the category count is calculated for all search results.<p>
405      *
406      * @return <code>true</code> if the category count is calculated for all search results
407      */

408     public boolean isCalculateCategories() {
409
410         return m_calculateCategories;
411     }
412
413     /**
414      * Creates a merged parameter set from this parameters, restricted by the given other parameters.<p>
415      *
416      * This is mainly intended for "search in search result" functions.<p>
417      *
418      * The restricted query is build of the queries of both parameters, appended with AND.<p>
419      *
420      * The lists in the restriction for <code>{@link #getFields()}</code>, <code>{@link #getRoots()}</code> and
421      * <code>{@link #getCategories()}</code> are <b>intersected</b> with the lists of this search parameters. Only
422      * elements containd in both lists are included for the created search parameters.
423      * If a list in either the restriction or in this search parameters is <code>null</code>,
424      * the list from the other search parameters is used direclty.<p>
425      *
426      * The values for
427      * <code>{@link #isCalculateCategories()}</code>
428      * and <code>{@link #getSort()}</code> of this parameters are used for the restricted parameters.<p>
429      *
430      * @param restriction the parameters to restrict this parameters with
431      * @return the restricted parameters
432      */

433     public CmsSearchParameters restrict(CmsSearchParameters restriction) {
434
435         // append queries
436
StringBuffer JavaDoc query = new StringBuffer JavaDoc(256);
437         if (getQuery() != null) {
438             // don't blow up unneccessary closures (if CmsSearch is reused and restricted several times)
439
boolean closure = !getQuery().startsWith("+(");
440             if (closure) {
441                 query.append("+(");
442             }
443             query.append(getQuery());
444             if (closure) {
445                 query.append(")");
446             }
447         }
448         if (restriction.getQuery() != null) {
449             // don't let lucene max terms be exceeded in case someone reuses a CmsSearch and continuously restricts
450
// query with the same restrictions...
451
if (query.indexOf(restriction.getQuery()) < 0) {
452                 query.append(" +(");
453                 query.append(restriction.getQuery());
454                 query.append(")");
455             }
456         }
457
458         // restrict fields
459
List JavaDoc fields = null;
460         if ((m_fields != null) && (m_fields.size() > 0)) {
461             if ((restriction.getFields() != null) && (restriction.getFields().size() > 0)) {
462                 fields = ListUtils.intersection(m_fields, restriction.getFields());
463             } else {
464                 fields = m_fields;
465             }
466         } else {
467             fields = restriction.getFields();
468         }
469
470         // restrict roots
471
List JavaDoc roots = null;
472         if ((m_roots != null) && (m_roots.size() > 0)) {
473             if ((restriction.getRoots() != null) && (restriction.getRoots().size() > 0)) {
474                 roots = ListUtils.intersection(m_roots, restriction.getRoots());
475                 // TODO: This only works if there are equal paths in both parameter sets - for two distinct sets
476
// all root restrictions are dropped with an empty list.
477
} else {
478                 roots = m_roots;
479             }
480         } else {
481             roots = restriction.getRoots();
482         }
483
484         // restrict categories
485
List JavaDoc categories = null;
486         if ((m_categories != null) && (m_categories.size() > 0)) {
487             if ((restriction.getCategories() != null) && (restriction.getCategories().size() > 0)) {
488                 categories = ListUtils.intersection(m_categories, restriction.getCategories());
489             } else {
490                 categories = m_categories;
491             }
492         } else {
493             categories = restriction.getCategories();
494         }
495
496         // create the new search parameters
497
CmsSearchParameters result = new CmsSearchParameters(
498             query.toString(),
499             fields,
500             roots,
501             categories,
502             m_calculateCategories,
503             m_sort);
504         result.setIndex(getIndex());
505         return result;
506     }
507
508     /**
509      * Set wether category counts shall be calculated for the corresponding search results or not.<p>
510      *
511      * @param flag true if category counts shall be calculated for the corresponding search results or false if not
512      */

513     public void setCalculateCategories(boolean flag) {
514
515         m_calculateCategories = flag;
516     }
517
518     /**
519      * Set the list of categories (strings) to this parameters. <p>
520      *
521      * @param categories the list of categories (strings) of this parameters
522      */

523     public void setCategories(List JavaDoc categories) {
524
525         m_categories = categories;
526     }
527
528     /**
529      * Sets the list of strings of names of fields to search in. <p>
530      *
531      * @param fields the list of strings of names of fields to search in to set
532      */

533     public void setFields(List JavaDoc fields) {
534
535         m_fields = fields;
536     }
537
538     /**
539      * Set the name of the index to search.<p>
540      *
541      *
542      * @param indexName the name of the index
543      */

544     public void setIndex(String JavaDoc indexName) {
545
546         CmsSearchIndex index;
547         if (CmsStringUtil.isNotEmpty(indexName)) {
548             try {
549                 index = OpenCms.getSearchManager().getIndex(indexName);
550                 if (index == null) {
551                     throw new CmsException(Messages.get().container(Messages.ERR_INDEX_NOT_FOUND_1, indexName));
552                 }
553                 setSearchIndex(index);
554             } catch (Exception JavaDoc exc) {
555                 if (LOG.isErrorEnabled()) {
556                     LOG.error(Messages.get().getBundle().key(Messages.LOG_INDEX_ACCESS_FAILED_1, indexName), exc);
557                 }
558             }
559         }
560     }
561
562     /**
563      * Sets the query to search for. <p>
564      *
565      * The decoding here is tailored for query strings that are
566      * additionally manually utf-8 encoded at client side (javascript) to get around an
567      * issue with special chars in applications that use non- utf-8 encoding
568      * (e.g. ISO-8859-1) OpenCms applications. It is not recommended to use this with
569      * frontends that don't encode manually as characters like sole "%" (without number suffix)
570      * will cause an Exception.<p>
571      *
572      * @param query the querye to search for to set
573      *
574      */

575     public void setQuery(String JavaDoc query) {
576
577         // query = CmsEncoder.decode(query);
578

579         // for widget use the exception is thrown here to enforce the errmsg next to widget
580
if (query.trim().length() < getQueryLength()) {
581             throw new CmsIllegalArgumentException(Messages.get().container(
582                 Messages.ERR_QUERY_TOO_SHORT_1,
583                 new Integer JavaDoc(getQueryLength())));
584         }
585         m_query = query;
586     }
587
588     /**
589      * Sets the minimum length of the search query.<p>
590      *
591      * @param length the minimum search query length
592      */

593     public void setQueryLength(int length) {
594
595         m_queryLength = length;
596     }
597
598     /**
599      * Sets the list of strings of roots to search under for the search.<p>
600      *
601      * @param roots the list of strings of roots to search under for the search to set
602      */

603     public void setRoots(List JavaDoc roots) {
604
605         m_roots = roots;
606     }
607
608     /**
609      * Set the comma separated search root names to restrict search to.<p>
610      *
611      * @param categories the comma separated category names to restrict search to
612      */

613     public void setSearchCategories(String JavaDoc categories) {
614
615         setCategories(CmsStringUtil.splitAsList(categories, ','));
616     }
617
618     /**
619      * Set wether the content field should be searched.<p>
620      *
621      * This method is a widget support for <code>{@link org.opencms.widgets.CmsCheckboxWidget}</code>.<p>
622      *
623      * @param flag true if the field <code>{@link org.opencms.search.documents.I_CmsDocumentFactory#DOC_CONTENT}</code>
624      * shall be searched - false else
625      */

626     public void setSearchFieldContent(boolean flag) {
627
628         if (flag) {
629             if (!m_fields.contains(I_CmsDocumentFactory.DOC_CONTENT)) {
630                 m_fields.add(I_CmsDocumentFactory.DOC_CONTENT);
631             }
632         } else {
633             m_fields.remove(I_CmsDocumentFactory.DOC_CONTENT);
634         }
635     }
636
637     /**
638      * Set wether the description field should be searched.<p>
639      *
640      * This method is a widget support for <code>{@link org.opencms.widgets.CmsCheckboxWidget}</code>.<p>
641      *
642      * @param flag true if the field <code>{@link org.opencms.search.documents.I_CmsDocumentFactory#DOC_DESCRIPTION}</code>
643      * shall be searched - false else
644      */

645     public void setSearchFieldDescription(boolean flag) {
646
647         if (flag) {
648             if (!m_fields.contains(I_CmsDocumentFactory.DOC_DESCRIPTION)) {
649                 m_fields.add(I_CmsDocumentFactory.DOC_DESCRIPTION);
650             }
651         } else {
652             m_fields.remove(I_CmsDocumentFactory.DOC_DESCRIPTION);
653         }
654     }
655
656     /**
657      * Set wether the title field should be searched.<p>
658      *
659      * This method is a widget support for <code>{@link org.opencms.widgets.CmsCheckboxWidget}</code>.<p>
660      *
661      * @param flag true if the field <code>{@link org.opencms.search.documents.I_CmsDocumentFactory#DOC_KEYWORDS}</code>
662      * shall be searched - false else
663      */

664     public void setSearchFieldKeywords(boolean flag) {
665
666         if (flag) {
667             if (!m_fields.contains(I_CmsDocumentFactory.DOC_KEYWORDS)) {
668                 m_fields.add(I_CmsDocumentFactory.DOC_KEYWORDS);
669             }
670         } else {
671             m_fields.remove(I_CmsDocumentFactory.DOC_KEYWORDS);
672         }
673     }
674
675     /**
676      * Set wether the meta field should be searched.<p>
677      *
678      * This method is a widget support for <code>{@link org.opencms.widgets.CmsCheckboxWidget}</code>.<p>
679      *
680      * @param flag true if the field <code>{@link org.opencms.search.documents.I_CmsDocumentFactory#DOC_META}</code>
681      * shall be searched - false else
682      */

683     public void setSearchFieldMeta(boolean flag) {
684
685         if (flag) {
686             if (!m_fields.contains(I_CmsDocumentFactory.DOC_META)) {
687                 m_fields.add(I_CmsDocumentFactory.DOC_META);
688             }
689         } else {
690             m_fields.remove(I_CmsDocumentFactory.DOC_META);
691         }
692     }
693
694     /**
695      * Set wether the title field should be searched.<p>
696      *
697      * This method is a widget support for <code>{@link org.opencms.widgets.CmsCheckboxWidget}</code>.<p>
698      *
699      * @param flag true if the field <code>{@link org.opencms.search.documents.I_CmsDocumentFactory#DOC_TITLE_INDEXED}</code>
700      * shall be searched - false else
701      */

702     public void setSearchFieldTitle(boolean flag) {
703
704         if (flag) {
705             if (!m_fields.contains(I_CmsDocumentFactory.DOC_TITLE_INDEXED)) {
706                 m_fields.add(I_CmsDocumentFactory.DOC_TITLE_INDEXED);
707             }
708         } else {
709             m_fields.remove(I_CmsDocumentFactory.DOC_TITLE_INDEXED);
710         }
711     }
712
713     /**
714      * Sets the search index to use for the search. <p>
715      *
716      * @param index the search index to use for the search to set.
717      *
718      * @throws CmsIllegalArgumentException if null is given as argument
719      */

720     public void setSearchIndex(CmsSearchIndex index) throws CmsIllegalArgumentException {
721
722         if (index == null) {
723             throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_INDEX_NULL_0));
724         }
725         m_index = index;
726     }
727
728     /**
729      * Set the search page to display. <p>
730      *
731      * @param page the search page to display
732      */

733     public void setSearchPage(int page) {
734
735         m_page = page;
736     }
737
738     /**
739      * Set the comma separated search root names to restrict search to.<p>
740      *
741      * @param rootNameList the comma separated search root names to restrict search to
742      */

743     public void setSearchRoots(String JavaDoc rootNameList) {
744
745         m_roots = CmsStringUtil.splitAsList(rootNameList, ',');
746     }
747
748     /**
749      * Set the instance that defines the sort order for search results.
750      *
751      * @param sortOrder the instance that defines the sort order for search results to set
752      */

753     public void setSort(Sort sortOrder) {
754
755         m_sort = sortOrder;
756     }
757
758     /**
759      * Sets the internal member of type <code>{@link Sort}</code> according to
760      * the given sort name. <p>
761      *
762      * For a list of valid sort names, please see <code>{@link #SORT_NAMES}</code>.<p>
763      *
764      * @param sortName the name of the sort to use
765      *
766      * @see #SORT_NAMES
767      */

768     public void setSortName(String JavaDoc sortName) {
769
770         if (sortName.equals(SORT_NAMES[1])) {
771             m_sort = SORT_DATE_CREATED;
772         } else if (sortName.equals(SORT_NAMES[2])) {
773             m_sort = SORT_DATE_LASTMODIFIED;
774         } else if (sortName.equals(SORT_NAMES[3])) {
775             m_sort = SORT_TITLE;
776         } else {
777             m_sort = SORT_DEFAULT;
778         }
779     }
780
781     /**
782      * @see java.lang.Object#toString()
783      */

784     public String JavaDoc toString() {
785
786         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
787         result.append("query:[");
788         result.append(m_query);
789         result.append("] ");
790         if ((m_fields != null) && (m_fields.size() > 0)) {
791             result.append("fields:[");
792             for (int i = 0; i < m_fields.size(); i++) {
793                 result.append(m_fields.get(i));
794                 if (i + 1 < m_fields.size()) {
795                     result.append(", ");
796                 }
797             }
798             result.append("] ");
799         }
800         if ((m_roots != null) && (m_roots.size() > 0)) {
801             result.append("roots:[");
802             for (int i = 0; i < m_roots.size(); i++) {
803                 result.append(m_roots.get(i));
804                 if (i + 1 < m_roots.size()) {
805                     result.append(", ");
806                 }
807             }
808             result.append("] ");
809         }
810         if ((m_categories != null) && (m_categories.size() > 0)) {
811             result.append("categories:[");
812             for (int i = 0; i < m_categories.size(); i++) {
813                 result.append(m_categories.get(i));
814                 if (i + 1 < m_categories.size()) {
815                     result.append(", ");
816                 }
817             }
818             result.append("] ");
819         }
820         if (m_calculateCategories) {
821             result.append("calculate-categories ");
822         }
823         result.append("sort:[");
824         if (m_sort == CmsSearchParameters.SORT_DEFAULT) {
825             result.append("default");
826         } else if (m_sort == CmsSearchParameters.SORT_TITLE) {
827             result.append("title");
828         } else if (m_sort == CmsSearchParameters.SORT_DATE_CREATED) {
829             result.append("date-created");
830         } else if (m_sort == CmsSearchParameters.SORT_DATE_LASTMODIFIED) {
831             result.append("date-lastmodified");
832         } else {
833             result.append("unknown");
834         }
835         result.append("]");
836         return result.toString();
837     }
838
839     private String JavaDoc toSeparatedString(List JavaDoc stringList, char c) {
840
841         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
842         Iterator JavaDoc it = stringList.iterator();
843         while (it.hasNext()) {
844             result.append(it.next());
845             if (it.hasNext()) {
846                 result.append(c);
847             }
848         }
849         return result.toString();
850     }
851 }
Popular Tags