Project

General

Profile

« Previous | Next » 

Revision 8464

Unify solr indexing with an IndexTask that is added to the queue -- allows us to send more than just the systemMetadata to the indexer. Initially this is for READ event counts for each document. https://projects.ecoinformatics.org/ecoinfo/issues/6346

View differences:

SolrIndexIT.java
1 1
package edu.ucsb.nceas.metacat.index;
2 2

  
3
import static org.junit.Assert.assertFalse;
3 4
import static org.junit.Assert.assertTrue;
4 5

  
5 6
import edu.ucsb.nceas.metacat.common.SolrServerFactory;
......
10 11
import java.io.StringWriter;
11 12
import java.io.Writer;
12 13
import java.util.ArrayList;
14
import java.util.HashMap;
13 15
import java.util.List;
16
import java.util.Map;
14 17

  
15 18
import org.apache.solr.client.solrj.SolrServer;
16 19
import org.apache.solr.client.solrj.SolrServerException;
......
128 131
    }
129 132
    
130 133
    
131
    /*
132
     * Do query
134
    /**
135
     * Test building index for dynamic fields.
133 136
     */
137
    @Test
138
    public void testDynamicFields() throws Exception {
139
    	
140
       SystemMetadata systemMetadata = TypeMarshaller.unmarshalTypeFromFile(SystemMetadata.class, SYSTEMMETAFILEPATH);
141
       InputStream emlInputStream = new FileInputStream(new File(EMLFILEPATH)); 
142
       Identifier pid = new Identifier();
143
       pid.setValue(id);
144
       solrIndex.update(pid, systemMetadata, emlInputStream);
145
       String result = doQuery(solrIndex.getSolrServer());
146
       List<String> ids = solrIndex.getSolrIds();
147
       boolean foundId = false;
148
       for(String identifiers :ids) {
149
           if (id.equals(identifiers)) {
150
               foundId = true;
151
           }
152
       }
153
       assertTrue(foundId);
154
       assertTrue(result.contains("version1"));
155
       
156
       // augment with the dynamic field
157
       String fieldName = "test_count_i";
158
       Map<String, List<Object>> fields = new HashMap<String, List<Object>>();
159
       List<Object> values = new ArrayList<Object>();
160
       values.add(6);
161
       fields.put(fieldName, values);
162
       solrIndex.insertFields(pid, fields);
163
       result = doQuery(solrIndex.getSolrServer(), "&fq=" + fieldName + ":[0 TO 5]");
164
       assertFalse(result.contains(id));
165
       result = doQuery(solrIndex.getSolrServer(), "&fq=" + fieldName + ":[6 TO 6]");
166
       assertTrue(result.contains(id));
167
       
168
       // now update the value
169
       values.clear();
170
       values.add(7);
171
       fields.put(fieldName, values);
172
       solrIndex.insertFields(pid, fields);
173
       result = doQuery(solrIndex.getSolrServer(), "&fq=" + fieldName + ":[7 TO 7]");
174
       assertTrue(result.contains(id));
175
       
176
    }
177
    
178
    /**
179
     * Do query - with no additional params
180
     */
134 181
    public static String doQuery(SolrServer server)
135 182
                    throws SolrServerException {
183
    	return doQuery(server, null);
184
    }
185
    
186
    /**
187
     * Do query, allowing additional parameters
188
     */
189
    public static String doQuery(SolrServer server, String moreParams)
190
                    throws SolrServerException {
136 191
                StringBuffer request = new StringBuffer();
137 192
                request.append("q=" + "*:*");
193
                if (moreParams != null) {
194
                    request.append(moreParams);
195
                }
138 196
                SolrParams solrParams = SolrRequestParsers.parseQueryString(request
139 197
                        .toString());
140 198
                QueryResponse reponse = server.query(solrParams);
......
146 204
                return result;
147 205
    }
148 206
    
149
    /*
207
    /**
150 208
     * Transform the query response to the xml format.
151 209
     */
152 210
    private static String toXML(SolrParams request, QueryResponse response) {

Also available in: Unified diff