Sep 25, 2018

solr create and query sample

bin/solr start
bin/solr stop
bin/solr create -c corename
bin/solr delete -c corename

bin/solr create -c contacts
bin/post -c contacts mycontacts.xml

mycontacts.xml
<add> 
   <doc> 
      <field name = "id">001</field> 
      <field name = "first name">Rajiv</field> 
      <field name = "last name">Reddy</field> 
      <field name = "phone">9848022337</field> 
      <field name = "city">Hyderabad</field> 
   </doc>  
   <doc> 
      <field name = "id">002</field> 
      <field name = "first name">Siddarth</field> 
      <field name = "last name">Battacharya</field> 
      <field name = "phone">9848022338</field> 
      <field name = "city">Kolkata</field> 
   </doc>  
   <doc> 
      <field name = "id">003</field> 
      <field name = "first name">Rajesh</field> 
      <field name = "last name">Khanna</field> 
      <field name = "phone">9848022339</field> 
      <field name = "city">Delhi</field> 
   </doc>  
   <doc> 
      <field name = "id">004</field> 
      <field name = "first name">Preethi</field> 
      <field name = "last name">Agarwal</field> 
      <field name = "phone">9848022330</field> 
      <field name = "city">Pune</field> 
   </doc>  
   <doc> 
      <field name = "id">005</field> 
      <field name = "first name">Trupthi</field> 
      <field name = "last name">Mohanthy</field> 
      <field name = "phone">9848022336</field> 
      <field name = "city">Bhuwaeshwar</field> 
   </doc> 
   <doc> 
      <field name = "id">006</field> 
      <field name = "first name">Archana</field> 
      <field name = "last name">Mishra</field> 
      <field name = "phone">9848022335</field> 
      <field name = "city">Chennai</field> 
   </doc> 
</add>

queries
http://localhost:8983/solr/contacts/select?q=*:*
http://localhost:8983/solr/contacts/select?q=phone:9848022337

case insensitive by default
http://localhost:8983/solr/contacts/select?q=first_name:TrUpThi - 1 docs
http://localhost:8983/solr/contacts/select?q=first_name:TrUpTh - 0 docs
http://localhost:8983/solr/contacts/select?q=first_name:TrUpTh* - 1 docs

schema.xml / managed-schema / select a core > schema
<field name="test1" type="text" indexed="false" stored="false" required="false" />
Typically you will want your field to be either indexed or stored or both. If you set both to false, that field will not be available in your Solr docs (either for searching or for displaying). https://stackoverflow.com/a/22298265/6729230

Before adding docs to solr specify schema represented in schema.xml file. IF indexed or stored need is set false. Solr creates fields in schema based on the data and sets both true.
not advisable to change the schema after the documents have been added to the index. (http://www.solrtutorial.com/basic-solr-concepts.html)

Indexed and stored
While posting first solr analyse the data - analysis - lower casing, removing word stems, etc.
Analysis :  produces tokens. they are not original text, tokens are what are searched when you perform a search query. Indexed fields are fields which undergo an analysis phase and added to the indx. If a field is not indexed it cannot be searched. We cannot show tokens to users. we need to show the original text - there comes stored = true.
Sometimes, there are fields which aren't searched, but need to be displayed in the search results. You accomplish that by setting the field attributes to stored=true and indexed=false. Storing inceases the size of the index - index is analogous to database in MySQL.
Doubts
  • what is the difference between managed-schema and schema.xml ?
  • what is the difference between collection and core ?
Delete all documents in a collection - the collection name is gbif




For Web Developer

  open -a "Google Chrome" --args --disable-web-security