1

Solr Version : 5.0

So I am working on Solr for first time, and really not understand perfectly. Here what I did :-

I have created a core named - search Then my schema.xml file has follwoing code :

<?xml version="1.0" encoding="UTF-8" ?>
<schema name="simple" version="1.5">

    <types>
        <fieldtype name='string' class='solr.StrField' />
        <fieldtype name='long' class='solr.TrieLongField' />
    </types>

<fields>

        <field name='id' type='int' required='true' indexed="true"/>
        <field name='name' type='text' required='true' indexed="true"/>


    </fields>

    <uniqueKey>id</uniqueKey>
    <defaultSearchField>fullText</defaultSearchField>
    <solrQueryParser defaultOperator='OR' />

</schema>

solrconfig.xml :

<?xml version='1.0' encoding='UTF-8' ?>
<config>
    <luceneMatchVersion>5.0.0</luceneMatchVersion>
    <lib dir="../../../../dist/" regex="solr-dataimporthandler-.*\.jar" />

    <requestHandler name="standard" class="solr.StandardRequestHandler" default='true' />
    <requestHandler name="/update" class="solr.UpdateRequestHandler" />
    <requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" />

     <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
      <lst name="defaults">
       <str name="config">db-data-config.xml</str>
      </lst>
    </requestHandler>

    <admin>
        <defaultQuery>*:*</defaultQuery>
    </admin>

</config>

db-data-config.xml :

<dataConfig>
  <dataSource type="JdbcDataSource"
            driver="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/solr"
            user="root"
            password="" /> 
  <document>
    <entity name="users" query="select id,name from users;" />
  </document>
</dataConfig>

I have created a database on PHPmyadmin please find below SG :

enter image description here

when I clicked query on solr panel then it shows empty why ?

enter image description here

Can anyone help me on this, as I am new to solr search. What I am doing wrong ?

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
Rakesh Shetty
  • 4,548
  • 7
  • 40
  • 79

2 Answers2

1

I dont see a field named "fulltext" in schema.xml but why its defined as the default search

<defaultSearchField>fullText</defaultSearchField>

change it

<defaultSearchField>name</defaultSearchField>

mention the fields in the data config xml

<field column="ID" name="id" /> 
<field column="NAME" name="name" />

your data-config should look alike

<dataConfig>
  <dataSource type="JdbcDataSource"
            driver="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/solr"
            user="root"
            password="" /> 
  <document>
    <entity name="users" query="select id,name from users">
     <field column="ID" name="id" /> 
     <field column="NAME" name="name" />
    </entity>
  </document>
</dataConfig>

add it as in schema.xml

    <types>
        <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
    <fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
    </types>
    <fields>
        <field name='id' type='int' required='true' indexed="true" stored="true"/> 
        <field name='name' type='string' required='true' indexed="true" stored="true"/> 
<fields>
Abhijit Bashetti
  • 8,518
  • 7
  • 35
  • 47
  • I have put mysql connecter jar file on solr dist folder and it work sucessfully. But I want to write a query for say suppose there is a name field having name "Rakesh Vasant Shetty" and "Rick V Smarty", then i want to search like '%Rakesh Shetty%' and it should display the result Rakesh Vasant Shetty – Rakesh Shetty May 11 '15 at 13:05
  • http://localhost:8080/solr/select/?q=name:Rakesh Shetty and if you have default search as name then http://localhost:8080/solr/select/?q=Rakesh Shetty – Abhijit Bashetti May 11 '15 at 13:53
  • can you please look into this question http://stackoverflow.com/questions/30186157/how-to-run-a-sql-query-in-solr – Rakesh Shetty May 12 '15 at 08:58
  • can you please look into that question – Rakesh Shetty May 12 '15 at 09:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/77594/discussion-between-rakesh-shetty-and-abhijit-bashetti). – Rakesh Shetty May 12 '15 at 10:02
0

Make the changes in your db-data-config.xml similar to what i have done

 <entity name="city_masters" pk="city_id" query="SELECT delete_status as  
city_masters_delete_status,city_id,country_id,city_name,city_updated  from   
city_masters> 
<field column="city_id" name="id"/> 
<field column="city_name" name="city_name" indexed="true" stored="true" />
<field column="country_id" name="country_id" indexed="true" stored="true" />

 <field column="city_masters_delete_status" name="city_masters_delete_status"   

      indexed="true" stored="true" />

     </entity>

You missed out the field column part.Add them like i have done for my code and it should work.If still doesnt work let me know

userMadhav
  • 144
  • 1
  • 12