Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with custom types/definitions being ignored #149

Open
peavers opened this issue Sep 10, 2017 · 7 comments
Open

Issue with custom types/definitions being ignored #149

peavers opened this issue Sep 10, 2017 · 7 comments
Labels

Comments

@peavers
Copy link

peavers commented Sep 10, 2017

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
Copy link
Author

peavers commented Sep 10, 2017

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
Copy link
Contributor

dhensby commented Sep 18, 2017

@tractorcow any ideas?

@tractorcow
Copy link

Could it be

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

Missing the fix from AuthorsPrefix?

@peavers
Copy link
Author

peavers commented Sep 19, 2017

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

@am071092
Copy link

Any update on this? Facing the same issue

@Firesphere
Copy link

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
Copy link

am071092 commented May 23, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants