Project

General

Profile

« Previous | Next » 

Revision 7726

Added by Jing Tao over 11 years ago

Imeplement the getSolrVersion, getSchemaField and getValidSchemaFields for the EmbeddedSolrServer.

View differences:

metacat-common/src/main/java/edu/ucsb/nceas/metacat/common/query/EmbeddedSolrQueryService.java
28 28

  
29 29
import java.io.IOException;
30 30
import java.io.InputStream;
31
import java.io.StringWriter;
32
import java.util.ArrayList;
31 33
import java.util.List;
32 34
import java.util.Map;
33 35
import java.util.Set;
......
38 40
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
39 41
import org.apache.solr.client.solrj.response.QueryResponse;
40 42
import org.apache.solr.common.params.SolrParams;
43
import org.apache.solr.common.util.XML;
41 44
import org.apache.solr.core.CoreContainer;
42 45
import org.apache.solr.core.SolrCore;
46
import org.apache.solr.schema.IndexSchema;
43 47
import org.apache.solr.schema.SchemaField;
44 48
import org.dataone.service.exceptions.NotFound;
45 49
import org.dataone.service.exceptions.NotImplemented;
......
60 64
    private CoreContainer coreContainer = null;
61 65
    private String collectionName = null;
62 66
    private SolrCore solrCore = null;
67
    private Map<String, SchemaField> fieldMap = null;
68
    private IndexSchema schema = null;
69
    private List<String> validSolrFieldNames = null;
70
    private String solrSpecVersion = "";
71
    
63 72
    /**
64 73
     * Constructor.
65 74
     * @param solrServer
......
83 92
        if(solrCore == null) {
84 93
            throw new NotFound("0000","EmbeddedSolrQueryService.constructor - There is no SolrCore named "+collectionName+".");
85 94
        }
95
        schema = solrCore.getSchema();
96
        fieldMap = schema.getFields();
86 97
    }
87 98
    /**
88 99
     * Query the Solr server with specified query and user's identity. If the Subjects
......
131 142
    
132 143
    
133 144
    /**
134
     * Get the fields list of the index schema
145
     * Get the fields map of the index schema
146
     * @return the fields map (the field name is the key and the SchemaField is the value).
147
     */
148
    public  Map<String, SchemaField> getIndexSchemaFields() {
149
        return fieldMap;
150
    }
151
    
152
    /**
153
     * Get the list of the valid field name (moved the fields names of the CopyFieldTarget).
135 154
     * @return
136
     * @throws Exception
137 155
     */
138
    public  Map<String, SchemaField> getIndexSchemaFields() throws Exception {
139
        return null;
156
    public List<String> getValidSchemaField() {
157
        if (validSolrFieldNames != null && validSolrFieldNames.isEmpty()) {
158
            //System.out.println("the valid file name is\n"+validSolrFieldNames);
159
            return validSolrFieldNames;
160
        } else {
161
            validSolrFieldNames = new ArrayList<String>();
162
            if(fieldMap != null) {
163
                Set<String> fieldNames = fieldMap.keySet();
164
                for(String fieldName : fieldNames) {
165
                    SchemaField field = fieldMap.get(fieldName);
166
                    //remove the field which is the target field of a CopyField.
167
                    if(field != null && !schema.isCopyFieldTarget(field)) {
168
                         validSolrFieldNames.add(fieldName);
169
                    }
170
                }
171
            }
172
            //System.out.println("the valid file name is\n"+validSolrFieldNames);
173
            return validSolrFieldNames;
174
        }
175
       
176
     
177
        
140 178
    }
141 179
    
142 180
    /**
......
144 182
     * @return
145 183
     */
146 184
    public String getSolrServerVersion() {
147
        return null;
185
        if( solrSpecVersion !=null ) {
186
            return solrSpecVersion;
187
        } else {
188
            Package p = SolrCore.class.getPackage();
189
            StringWriter tmp = new StringWriter();
190
            solrSpecVersion = p.getSpecificationVersion();
191
            if (null != solrSpecVersion) {
192
                try {
193
                    XML.escapeCharData(solrSpecVersion, tmp);
194
                } catch (IOException e) {
195
                    e.printStackTrace();
196
                }
197
                solrSpecVersion = tmp.toString();
198
            }
199
            if (solrSpecVersion == null || solrSpecVersion.trim().equals("")) {
200
                solrSpecVersion = UNKNOWN;
201
            } 
202
            return solrSpecVersion;
203
        }
148 204
    }
149 205
}
metacat-common/src/main/java/edu/ucsb/nceas/metacat/common/query/HttpSolrQueryService.java
153 153
        return null;
154 154
    }
155 155
    
156
    /**
157
     * Get the list of the valid field name (moved the fields names of the CopyFieldTarget).
158
     * @return
159
     */
160
    public List<String> getValidSchemaField() {
161
        return null;
162
    }
156 163
 
157 164
}
metacat-common/src/main/java/edu/ucsb/nceas/metacat/common/query/SolrQueryService.java
54 54
    public static final String WT = "wt";//the property name to specify the return type
55 55
    
56 56
    protected static final String FILTERQUERY = "fq";
57
    protected static final String UNKNOWN = "Unknown";
57 58
    private static final String READPERMISSION = "readPermission";
58 59
    private static final String RIGHTSHOLDER = "rightsHolder";
59 60
    private static final String OPENPARENTHESE = "(";
......
110 111
     */
111 112
    public abstract String getSolrServerVersion();
112 113
    
114
    /**
115
     * Get the list of the valid field name (moved the fields names of the CopyFieldTarget).
116
     * @return
117
     */
118
    public abstract List<String> getValidSchemaField();
113 119
    
114
    
115 120
    /**
116 121
     * If the solr server supports the specified wt.
117 122
     * @param wt

Also available in: Unified diff