silverstripe / silverstripe-fulltextsearch

Adds external full text search engine support to Silverstripe
BSD 3-Clause "New" or "Revised" License
44 stars 83 forks source link

Issue with custom types/definitions being ignored #149

Open peavers opened 7 years ago

peavers commented 7 years ago

Hello,

Attempting to use a custom type and definition when searching but it doesn't seem to be used at all.

SearchPeopleIndex.php

class SearchPeopleIndex extends SolrIndex
{
    public function init()
    {
        $this->addClass('SiteTree');
        $this->addClass('Person');
        $this->addFulltextField('AuthorName');
        $this->addCopyField('Person_AuthorName', 'AuthorsPre');
    }

    /**
     * @return mixed
     */
    public function getTypes()
    {
        return $this->renderWith(Director::baseFolder() . '/people-finder/core/templates/types.ss');
    }

    /**
     * @return string
     */
    function getFieldDefinitions()
    {
        $parent = parent::getFieldDefinitions();
        $parent .= $this->renderWith(Director::baseFolder() . '/people-finder/core/templates/definitions.ss');
        return $parent;
    }
}

Types.ss

[...]
<fieldType name="AuthorsPrefix" class="solr.TextField"  positionIncrementGap="100">
    <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory" />
        <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="200" side="front"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory" />
    </analyzer>
</fieldType>

Definitions.ss

<field name="AuthorsPre" type="AuthorsPrefix" indexed="true" multiValued="true"/>

In theory I should be able to search for John S and get a result for John Snow, however I get zero results. When I search for John I get John Snow, and when I search for Snow I also get John Snow, just not when searching for John S...

The query going to Solr looks like

[SearchPeopleIndex] webapp=/solr path=/select params={q=%2Bjohn+%2Bs&json.nl=map&fq=%2B(ClassName:Person)&rows=20&wt=json} hits=0 status=0 QTime=0

Any tips or pointers for how to get this working?

peavers commented 7 years ago

Further to note: When executing the query for John S via the Solr admin panel, I get the exact results I'm expecting. The only thing I can think of so far is how the query is encoded before being sent through to Solr. Specifically the %2B being added?

dhensby commented 7 years ago

@tractorcow any ideas?

tractorcow commented 7 years ago

Could it be

$this->addCopyField('Person_AuthorName', 'AuthorsPre');

Missing the fix from AuthorsPrefix?

peavers commented 7 years ago

No because AuthorsPre is the name of the field in the Definitions file, which uses the AuthorsPrefix type.

am071092 commented 5 years ago

Any update on this? Facing the same issue

Firesphere commented 5 years ago

Yes, I think @peavers is on the right track. The %2B and + sign are possibly the cause of this, converting + in to +%2B, which should not happen usually.

I think I have a fix somewhere, but it's pretty ugly

am071092 commented 5 years ago

It wasn't working for me because of the missing quotes in After: #cwpsearch. The doc needs to be updated. https://github.com/silverstripe/cwp/blob/master/docs/en/02_Features/01_Solr_search/07_Searching_documents.md


Name: mysearchconfig After: #cwpsearch

SilverStripe\Core\Injector\Injector: CWP\Search\CwpSearchEngine.search_index: class: MySolrSearchIndex