Name Search on Solr

妖精的绣舞 提交于 2019-12-25 03:52:59

问题


Apologies if I am posting a duplicated question, if so please point me to original question.

I am a solr novice and trying to achieve ordered word name search using solr.I am expecting following response from solr

Name                Search Term         Result
Thomas Alva Edison  Thomas              Match
Thomas Alva Edison  Alva                Match
Thomas Alva Edison  Edison              Match
Thomas Alva Edison  Thomas Edison       Match
Thomas Alva Edison  Thomas Alva         Match
Thomas Alva Edison  Alva Edison         Match
Thomas Alva Edison  Thomas Alva Edison  Match
Thomas Alva Edison  homas               No Match
Thomas Alva Edison  Edison Thomas       No Match
Thomas Alva Edison  homas edison        No Match
Thomas Alva Edison  homas dison         No Match

I am generating queries using MethodName using spring data solr. Please help me how I should form my schema to index this data and what filters I should use ?

Also guide me how to form the queries using methodName using spring data solr from appropriate result.


回答1:


Your schema.xml may be the one delivered with solr because there is already a field named name (tokenized and indexed) in there as follows:

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

so all you need to do is to create a document on that index:

curl localhost:8983/solr/collection1/update/json?commit=true -H 'Content-type:application/json' -d '
[
  {
    "id" : "1",
    "name" : "Thomas Edison"
  }
]'

You probably have a java class representing your document structure more or less as follows:

@SolrDocument(solrCoreName = "collection1")
public class Person {

    @Id
    private Long id;
    @Indexed
    private String name;

    // setters and getters

}

and a repository as follows:

public interface PersonDao extends SolrCrudRepository<Person, Long> {

    // derivable method names here

}

in order to have a search based on name you can declare the following method:

List<Person> findByName(String name);

As the field is tokenized, it will search for the provided parameter within a token from that field. This will lead to the results you are expecting.




回答2:


For that rather specific need, no filter/tokenizer comes to my mind.

What you can try is SurroundQueryParser (have not tried it my self)

If that will not work for you as sad as that can be, if I where you, I would consider customization of some kind:

  • Solr filter plugin that would produce required tokens (something similar to Shingle filter)
  • Create filed on the doc that would hold only allowed matches and use something like keyword tokenizer to enforce order


来源:https://stackoverflow.com/questions/32615687/name-search-on-solr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!