Follow Us:

Call Now! +39 0761 1916790

Solr SPARQL Endpoint in Two Minutes

How to store and query RDF data in Solr? Let’s do that in 2 minutes / 5 steps!

Step #1: What we need?

  • A shell  (in case you are on the dark side of the moon, all steps can be easily done in Eclipse or whatever IDE)
  • Java (7)
  • Apache Maven (3.x)
  • git 

Step #2: Checkout SolRDF

Open a shell and type the following:

> cd /tmp
> git clone https://github.com/SeaseLtd/SolRDF.git solrdf-download

Step #3: Build and Run SolRDF

> cd solrdf-download/solrdf
> mvn clean install
> cd solrdf-integration-tests 
> mvn clean package cargo:run

The very first time you run this command a lor of things will be downloaded, Solr included. At the end you should see something like this:

[INFO] Jetty 7.6.15.v20140411 Embedded started on port [8080] 
[INFO] Press Ctrl-C to stop the container...

Congrats! SolRDF is up and running!

Step #4: Add Some Data

Open another shell and type the following:

> curl -v http://localhost:8080/solr/store/update/bulk?commit=true \
  -H "Content-Type: application/n-triples" \
  --data-binary \
  @/tmp/solrdf-download/solrdf/src/test/resources/sample_data/bsbm-   generated-dataset.nt 

Wait a moment…ok! You’ve added (about) 5000 triples!

Step #5: Query

Open another shell and type the following:

> curl "http://127.0.0.1:8080/solr/store/sparql" \
  --data-urlencode "q=SELECT * WHERE { ?s ?p ?o } LIMIT 10" \
  -H "Accept: application/sparql-results+json"

...

> curl "http://127.0.0.1:8080/solr/store/sparql" \
  --data-urlencode "q=SELECT * WHERE { ?s ?p ?o } LIMIT 10" \
  -H "Accept: application/sparql-results+xml"

Et voilà!

Andrea Gazzarini

Andrea Gazzarini is a curious software engineer, mainly focused on the Java technology. He strongly loves coding and definitely likes to be considered a developer. Andrea has more than 15 years of experience in various software engineering areas, from telecommunications to banking. He has worked for several medium- and large-scale companies, such as IBM and Orga Systems. Andrea has several certifications in the Java programming language (programmer, developer, web component developer, business component developer, and JEE architect), BEA products (build and portal solutions), and Apache Solr (Lucid Apache Solr/Lucene Certified Developer).

No Comments

Post a Comment

Comment
Name
Email
Website