Project

General

Profile

« Previous | Next » 

Revision 8872

Added by Jing Tao over 9 years ago

Add code to determine if a id exists in a solr server.

View differences:

HttpSolrQueryService.java
22 22
import java.io.InputStream;
23 23
import java.net.MalformedURLException;
24 24
import java.net.URL;
25
import java.util.ArrayList;
26
import java.util.HashMap;
25 27
import java.util.List;
26 28
import java.util.Map;
27 29
import java.util.Set;
30
import java.util.Vector;
28 31

  
29 32
import javax.xml.parsers.DocumentBuilder;
30 33
import javax.xml.parsers.DocumentBuilderFactory;
31 34
import javax.xml.parsers.ParserConfigurationException;
32 35
import javax.xml.xpath.XPathConstants;
36
import javax.xml.xpath.XPathExpressionException;
33 37
import javax.xml.xpath.XPathFactory;
34 38

  
35 39
import org.apache.commons.codec.net.URLCodec;
36 40
import org.apache.commons.logging.Log;
37 41
import org.apache.commons.logging.LogFactory;
42
import org.apache.solr.client.solrj.SolrServerException;
38 43
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
44
import org.apache.solr.client.solrj.response.QueryResponse;
39 45
import org.apache.solr.client.solrj.util.ClientUtils;
40 46
import org.apache.solr.common.params.SolrParams;
41 47
import org.apache.solr.core.SolrConfig;
48
import org.apache.solr.schema.FieldType;
42 49
import org.apache.solr.schema.IndexSchema;
43 50
import org.apache.solr.schema.SchemaField;
51
import org.apache.solr.schema.TextField;
44 52
import org.dataone.configuration.Settings;
45 53
import org.dataone.service.exceptions.NotFound;
54
import org.dataone.service.exceptions.NotImplemented;
55
import org.dataone.service.types.v1.Identifier;
46 56
import org.dataone.service.types.v1.Subject;
57
import org.w3c.dom.Attr;
47 58
import org.w3c.dom.Document;
59
import org.w3c.dom.Element;
48 60
import org.w3c.dom.Node;
49 61
import org.w3c.dom.NodeList;
62
import org.xml.sax.Attributes;
50 63
import org.xml.sax.InputSource;
51 64
import org.xml.sax.SAXException;
52 65

  
......
306 319
        return doc;
307 320
    }
308 321
    
322
    /**
323
     * If there is a solr doc for the given id.
324
     * @param id - the specified id.
325
     * @return true if there is a solr doc for this id.
326
     */
327
    public boolean hasSolrDoc(Identifier id) throws ParserConfigurationException, SolrServerException, IOException, SAXException {
328
    	boolean hasIt = false;
329
    	if(id != null && id.getValue() != null && !id.getValue().trim().equals("") ) {
330
    		SolrParams query = EmbeddedSolrQueryService.buildIdQuery(id.getValue());
331
            QueryResponse response = httpSolrServer.query(query);
332
            hasIt = EmbeddedSolrQueryService.hasResult(response);
333
    	}
334
    	return hasIt;
335
    }
336
    
309 337
 
310 338
}

Also available in: Unified diff