Why is solr returning result with only exact searc

2019-09-12 16:49发布

I have created a core, secondCore{id, resid, title, name, cat, role, exp} Consider a sample data: {"id" : "11","resid" : 384,"title" : "perl and java developer","name" : "appnede new name","cat" : "22,11","role" : "new role","exp" : 1 }. When I search for title:perl, I get 0 result. I get mentioned result, only if I search for title:"perl and java developer" or title:perl*. Response:

<response>

<lst name="responseHeader">
  <int name="status">0</int>
  <int name="QTime">2</int>
  <lst name="params">
    <str name="indent">true</str>
    <str name="q">title:perl*</str>
    <str name="_">1444371225114</str>
    <str name="wt">xml</str>
  </lst>
</lst>
<result name="response" numFound="1" start="0">
  <doc>
    <str name="id">11</str>
    <arr name="resid">
      <long>384</long>
    </arr>
    <arr name="title">
      <str>perl and java developer</str>
    </arr>
    <arr name="name">
      <str>appnede new name</str>
    </arr>
    <arr name="cat">
      <long>2211</long>
    </arr>
    <arr name="role">
      <str>new role</str>
    </arr>
    <arr name="exp">
      <long>1</long>
    </arr>
    <long name="_version_">1514531870450122752</long></doc>
</result>
</response>

Also, why response is in arr <arr name="role"><str>new role</str></arr>? I want it in <str name="role">new role</str> and so with other fileds also. How to do? I'm using solr 5.3.0.

2条回答
来,给爷笑一个
2楼-- · 2019-09-12 17:31

Resolved above thing. I have changed field type to text_general_new, a new fieldType similar to text_general with some customization.
Alternatively, you can use text_general with multiValued="false". These changes needs to be done in managed-schema file. This is an implicit schema file used by solr.

But I have one more doubt here, as a beginner. Solr implicitly used managed-schema as replacement of schema.xml, but from where it came to know about fields in JSON file? I mean, it have already defined field for each field present in my JSON. How did it came to know? Which file (with location) is responsible for this?

查看更多
3楼-- · 2019-09-12 17:34

I think you have defined your field as string instead of text. String field does exact match whereas a text field will get you the results you are looking for.

Check out this other answer also : https://stackoverflow.com/a/7187441/147306

查看更多
登录 后发表回答