Boopathy
Boopathy

Reputation: 367

select in solr search is not working

I have configured solr, such that, it can index records from postgres database. It's uploaded successfully. And if I pass query string as *:*, it produce a response of all rows in the table. But when i specify the search, the result is always 0.

My XML response when query string *:* is:

<?xml version="1.0" encoding="UTF-8" ?> 

<response>
  <lst name="responseHeader">
   <int name="status">0</int> 
   <int name="QTime">0</int> 
   <lst name="params">
      <str name="q">*:*</str> 
   </lst>
 </lst>
 <result name="response" numFound="3" start="0">
 <doc>
<str name="names">sample1</str> 
<str name="sno">1</str> 
<str name="values">3</str> 
</doc>
 <doc>
<str name="names">sample2</str> 
<str name="sno">2</str> 
<str name="values">2</str> 
</doc>
<doc>
<str name="names">sample3</str> 
<str name="sno">3</str> 
<str name="values">4</str> 
</doc>
</result>
</response>

And my response when query string q=sample1 is:

<?xml version="1.0" encoding="UTF-8" ?> 

<response>
  <lst name="responseHeader">
   <int name="status">0</int> 
   <int name="QTime">0</int> 
   <lst name="params">
      <str name="q">*:*</str> 
   </lst>
 </lst>
 <result name="response" numFound="0" start="0" /> 
</response>

Thanks in advance.

Upvotes: 0

Views: 712

Answers (2)

P-S
P-S

Reputation: 4026

I ran a test project based on the default example provided in Solr 6.6.2 with MySql integration (assuming it's kinda related to your integration with postgres). I had this problem which turned out to be simply the naming of the fields.

In the config file for DataImportHandler (in most "Solr tutorial to index database" tutorials, it's called data-config.xml), the name of the <field> element must also be in the schema.xml file. I used the configs from the default examples that ship with Solr, there the field to query is _text_.

It's this line in the data-config.xml file below: <field column="name" name="_text_"/>

data-config.xml

<dataConfig>
    <dataSource type="JdbcDataSource" 
        driver="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost:3306/mydb1" 
        user="root" 
        password=""/>
        <document>
            <entity name="product" pk="id"
                query="select id,name from products"
                deltaImportQuery="SELECT id,name from products WHERE id='${dih.delta.id}'"
                deltaQuery="SELECT id FROM products  WHERE updated_at > '${dih.last_index_time}'"
                >
                <field column="id" name="id"/>
                <field column="name" name="_text_"/> 
            </entity>
        </document>
</dataConfig>

Schema.xml (must contain the following entry):

<field name="_text_" type="text_general" indexed="true" stored="true"/>

After fixing that, queries such as /select?q=foo returned non-empty results.

Upvotes: 0

Mike R.
Mike R.

Reputation: 558

q, by itself will search in whatever field defined in defaultSearchField (in schema.xml).

If you were to copy all your interesting text into the default field, that search would work. Alternatively, you could pass the field name in your query. q=names:sample1 should also return results.

Upvotes: 2

Related Questions