1
2
3
4
5
6
7
8
9
10
11
12
13
14 package net.sf.mmapps.modules.lucenesearch;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.mmbase.bridge.Cloud;
22
23 /***
24 * Holds all indexes
25 *
26 * @author Wouter Heijke
27 * @version $Revision: 1.1 $
28 */
29 public class SearchConfig {
30 private static Log log = LogFactory.getLog(SearchConfig.class);
31
32 private List indexList = new ArrayList();
33
34 private String defaultindex = null;
35
36 /***
37 * Collects all indexes
38 *
39 * @param cloud MMBase cloud to use for indexing
40 */
41 protected void collectAll(Cloud cloud) {
42 for (int i = 0; i < indexList.size(); i++) {
43 SearchIndex idx = (SearchIndex) indexList.get(i);
44 idx.collectAll(cloud);
45 }
46 }
47
48 /***
49 * Returns the name of an index object by name
50 *
51 * @param name Name of the index to look for
52 * @return The SearchIndex object
53 */
54 public SearchIndex getIndex(String name) {
55 for (int i = 0; i < indexList.size(); i++) {
56 SearchIndex idx = (SearchIndex) indexList.get(i);
57 if (idx.getName().equalsIgnoreCase(name)) {
58 return idx;
59 }
60 }
61 return null;
62 }
63
64 /***
65 * Returns an index by id
66 *
67 * @param id Number of the index in the list
68 * @return The SearchIndex object
69 */
70 public SearchIndex getIndex(int id) {
71 SearchIndex idx = (SearchIndex) indexList.get(id);
72 return idx;
73 }
74
75 /***
76 * @return default index
77 */
78 public SearchIndex getDefaultIndex() {
79 return defaultindex != null ? getIndex(defaultindex) : getIndex(0);
80 }
81
82 /***
83 * Adds an SearchIndex object
84 *
85 * @param index The SearchIndex object to add
86 */
87 public void addIndex(SearchIndex index) {
88 indexList.add(index);
89 log.info("INDEX: " + index.getName());
90 }
91
92 /***
93 * @param defaultindex
94 */
95 public void setDefaultIndexName(String defaultindex) {
96 this.defaultindex = defaultindex;
97 }
98
99 public String setDefaultIndexName() {
100 return defaultindex;
101 }
102
103 /***
104 * Returns the number of indexes available in this object
105 *
106 * @return the amount of indices
107 * @author Kees Jongenburger
108 */
109 public int getIndexCount() {
110 return indexList.size();
111 }
112 }