Wednesday 29 September 2010 2:31:14 am
I'm using the 2.1.0-final version of eZ find. I want to search for part of a word/name instead of the complete word, e.g., when I search for 'seb', I also want to find 'sebastiaan'.It is possible using the wildcard (*), but I want to keep things simple for the end users. In ezfind/java/solr/conf/schema.xml I made a copy of the field info for:
<fieldType name="text" class="solr.TextField" positionIncrementGap="100"> and called it:
<fieldType name="text_staff" class="solr.TextField" positionIncrementGap="100"> In this new fieldtype called 'text_staff' I then changed:
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/> to
<analyzer type="index">
<tokenizer class="solr.NGramTokenizerFactory" minGramSize="3" maxGramSize="15" /> I define a new field in the <fields> section:
<field name="ezf_staff_text" type="text_staff" indexed="true" stored="true" multiValued="true" termVectors="true"/> I then added the following line to the copyFields:
<copyField source="attr_firstname_s" dest="ezf_staff_text"/>
<copyField source="attr_lastname_s" dest="ezf_staff_text"/> Finally, in the file ezfind\classes\ezfezpsolrquerybuilder.php I change the following code around line 262 from: $highLightFields = $queryFields;
$queryFields[] = eZSolr::getMetaFieldName( 'name' );
$queryFields[] = eZSolr::getMetaFieldName( 'owner_name');
to
$highLightFields = $queryFields;
$queryFields[] = eZSolr::getMetaFieldName( 'name' );
$queryFields[] = eZSolr::getMetaFieldName( 'owner_name' );
$queryFields[] = eZSolr::getFieldName( 'ezf_staff_text' ); And it works. However, it seems like a lot of changes to get the search for partial words working. Am I overdoing it? Did I miss something easier?
Thanks, Sebastiaan
Certified eZ publish developer with over 9 years of eZ publish experience. Available for challenging eZ publish projects as a technical consultant, project manager, trouble shooter or strategic advisor.
|