Forums / Extensions / eZ Find / Search for 'seb' instead of 'sebastiaan'

Search for 'seb' instead of 'sebastiaan'

Author Message

Sebastiaan van der Vliet

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.

Matthieu Sévère

Wednesday 29 September 2010 4:32:19 am

This is a smart workaround. But as you said quite complicated, I'm also interesting to see if there is a simpler solution.

--
eZ certified developer: http://ez.no/certification/verify/346216

Ivo Lukac

Wednesday 29 September 2010 6:38:51 am

Why not just copying into "ezf_df_text" solr field, then you don't need to hack ezfind code....

Changing schema.xml is normal ;)

http://www.linkedin.com/in/ivolukac
http://www.netgen.hr/eng/blog
http://twitter.com/ilukac

Sebastiaan van der Vliet

Wednesday 29 September 2010 7:05:56 am

Hi Ivo, I don't like changing the default/standard Solr field settings. For one reason, I am not sure what it would do to the size of the entire index if all text fields are indexed like the staff_text. I also think that using the ezf_df_text solr field would still require adding the line below to ezfezpsolrquerybuilder.php.

$queryFields[] = eZSolr::getFieldName( 'ezf_df_text' );

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.

Paul Borgermans

Wednesday 29 September 2010 11:21:53 am

"

Hi Ivo, I don't like changing the default/standard Solr field settings. For one reason, I am not sure what it would do to the size of the entire index if all text fields are indexed like the staff_text. I also think that using the ezf_df_text solr field would still require adding the line below to ezfezpsolrquerybuilder.php.

$queryFields[] = eZSolr::getFieldName( 'ezf_df_text' );
"

Hi all

Ngram tokenisation is something that can inflate your index pretty badly.

@Sebastiaan: I'll patch ezfind soonish so you can have better control on what field types are used (along some more in this realm)

Take care you do the Ngram tokenisation only at index time, not query time.

Another approach that is taken sometimes is to use a synonym filter (at query time) to have fine grained control ... ngrams .. well ... are sometimes very useful, but can lead to many confusing search results as well.

hth

Paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

eZ debug

Timing: Jan 29 2025 13:38:34
Script start
Timing: Jan 29 2025 13:38:34
Module start 'content'
Timing: Jan 29 2025 13:38:34
Module end 'content'
Timing: Jan 29 2025 13:38:34
Script end

Main resources:

Total runtime0.2805 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0079 588.0781180.7813
Module start 'content' 0.00790.0063 768.8594103.2578
Module end 'content' 0.01430.2661 872.1172535.1875
Script end 0.2804  1,407.3047 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00341.2127200.0002
Check MTime0.00120.4444200.0001
Mysql Total
Database connection0.00080.270210.0008
Mysqli_queries0.231782.61391410.0016
Looping result0.00130.44631390.0000
Template Total0.265894.810.2658
Template load0.00070.259510.0007
Template processing0.265194.506910.2651
Override
Cache load0.00050.180410.0005
Sytem overhead
Fetch class attribute can translate value0.00090.312710.0009
XML
Image XML parsing0.00040.125610.0004
General
dbfile0.00913.2539200.0005
String conversion0.00000.002830.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs