5

I'm working on auto completion search with Solr using EdgeNGrams. If the user is searching for names of employees, then auto completion should be applied. That is, I want the results to be like a Google search. It's working fine for some searches.

File schema.xml:

<fieldType name="edgytext" class="solr.TextField" positionIncrementGap="100" omitNorms="true">
    <analyzer type="index">
        <tokenizer class="solr.KeywordTokenizerFactory" />
        <filter class="solr.LowerCaseFilterFactory" />
        <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="solr.KeywordTokenizerFactory" />
        <filter class="solr.LowerCaseFilterFactory" />
        <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="15" side="front" />
    </analyzer>

<field name="title" type="edgytext" indexed="true" stored="true" omitNorms="true" omitTermFreqAndPositions="true"/>
<field name="empname" type="edgytext" indexed="true" stored="true" omitNorms="true" omitTermFreqAndPositions="true" />

<field name="autocomplete_text" type="edgytext" indexed="true" stored="false"  multiValued="true" omitNorms="true" omitTermFreqAndPositions="false" />
<copyField source="empname" dest="autocomplete_text"/>

<copyField source="title" dest="autocomplete_text"/>

 http://local:8080/test/suggest/?q=michael

Result:

<?xml version="1.0" encoding="UTF-8" ?>
<response>
    <lst name="responseHeader">
        <int name="status">0</int>
        <int name="QTime">1</int>
    </lst>
    <result name="response" numFound="0" start="0" />
    <lst name="spellcheck">
        <lst name="suggestions">
            <lst name="michael">
                <int name="numFound">9</int>
                <int name="startOffset">0</int>
                <int name="endOffset">7</int>
                <arr name="suggestion">
                    <str>michael bolton</str>
                    <str>michael foret</str>
                    <str>michael houser</str>
                    <str>michael o'brien</str>
                    <str>michael penn</str>
                    <str>michael row your boat ashore</str>
                    <str>michael tilson thomas</str>
                    <str>michael w. smith</str>
                    <str>michael w. smith featuring andrae crouch</str>
                </arr>
            </lst>
            <str name="collation">michael bolton</str>
        </lst>
    </lst>
</response>

It's working fine for me. When I search with michael f

http:// local:8080/test/suggest/?q=michael f

I get a response like:

<?xml version="1.0" encoding="UTF-8" ?>
<response>
    <lst name="responseHeader">
        <int name="status">0</int>
        <int name="QTime">1</int>
    </lst>
    <result name="response" numFound="0" start="0" />
    <lst name="spellcheck">
        <lst name="suggestions">
            <lst name="michael">
                <int name="numFound">9</int>
                <int name="startOffset">0</int>
                <int name="endOffset">7</int>
                <arr name="suggestion">
                    <str>michael bolton</str>
                    <str>michael foret</str>
                    <str>michael houser</str>
                    <str>michael o'brien</str>
                    <str>michael penn</str>
                    <str>michael row your boat ashore</str>
                    <str>michael tilson thomas</str>
                    <str>michael w. smith</str>
                    <str>michael w. smith featuring andrae crouch</str>
                </arr>
            </lst>
            <lst name="f">
                <int name="numFound">10</int>
                <int name="startOffset">8</int>
                <int name="endOffset">9</int>
                <arr name="suggestion">
                    <str>f**k the facts</str>
                    <str>fairest lord jesus</str>
                    <str>fatboy slim</str>
                    <str>ffh</str>
                    <str>fiona apple</str>
                    <str>foo fighters</str>
                    <str>frank sinatra</str>
                    <str>frans bauer</str>
                    <str>franz ferdinand</str>
                    <str>françois rauber</str>
                </arr>
            </lst>
            <str name="collation">michael bolton f**k the facts</str>
        </lst>
    </lst>
</response>.

When I search with michael f then, I should get michael foret only. Data coming starts with f. Is there anything wrong in my configuration settings in Solr?

4

1 回答 1

7

我写了 [旧链接] 关于使用 Solr 进行自动建议的不同方法以及您应该问自己一些问题以便做出正确的选择。简而言之,开箱即用的方法是:

  • 刻面前缀
  • NGrams
  • 条款组件
  • 推荐人

它们都有优点和局限性,我建议你阅读这篇文章。

如果您正在寻找一个完整且灵活的解决方案,这需要更多的工作,您也可以看看这篇文章

如果您已经决定使用 NGrams,给定您的示例,您可以使用EdgeNGramFilterFactory和 minGramSize 1 为您的员工编制索引,然后在该字段上搜索以进行自动建议。对于客户端部分,您需要使用一些 javascript。

于 2012-08-01T07:40:42.750 回答