Starting, stopping, indexing, clearing indexes and dealing with search results in Solr

To start solr with the default Jetty server, go to the solr installation directory/example
[code lanugage=”text”]
java -jar start.jar
[/code]

To start and run solr in the background
[code language=”text”]
java -jar start.jar &
[/code]

To stop solr in windows, press Ctrl-C.

To stop solr in nix os, press Ctrl-C if it running on the foreground. If it’s running in the background, find the pid by
[code language=”text”]
ps -ef | grep "start.jar"
[/code]

Assume the pid for the solr is 125647, type the following to stop solr
[code language=”text”]
kill -9 125647
[/code]

Indexing the sample data that came with the solr download, go to example/exampledocs/
[code language=”text”]
java -jar post.jar solr.xml monitor.xml
[/code]

To index all the sample data.
[code language=”text”]
java -jar post.jar *.xml
[/code]

To delete a document, for example the document with id SP2514N
[code language=”text”]
java -Ddata=args -Dcommit=no -jar post.jar "<delete><id>SP2514N</id></delete>"
java -jar post.jar
[/code]

To delete a document by query
[code language=”text”]
java -Ddata=args -jar post.jar "<delete><query>name:DDR</query></delete>"
[/code]

To delete all documents from the index by command line
[code language=”text”]
curl http://localhost:8983/solr/update –data ‘<delete><query>*:*</query></delete>’ -H ‘Content-type:text/xml; charset=utf-8’
curl http://localhost:8983/solr/update –data ‘<commit/>’ -H ‘Content-type:text/xml; charset=utf-8’
[/code]

To delete all documents from the index by http call from a browser
[code language=”text”]
http://localhost:8983/solr/update?stream.body=<delete><query>*:*</query></delete>
http://localhost:8983/solr/update?stream.body=<commit/>
[/code]

Example of dealing solr search results by php
[code language=”php”]
<?php
$code = file_get_contents(‘http://localhost:8983/solr/select/?q=sku%3A0123364356&wt=php’);
eval("\$result = " . $code . ";");
print_r($result);
?>
[/code]

Search within Codexpedia

Custom Search

Search the entire web

Custom Search