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

Exclude search fields #3

Open
riker09 opened this issue Dec 2, 2014 · 7 comments
Open

Exclude search fields #3

riker09 opened this issue Dec 2, 2014 · 7 comments

Comments

@riker09
Copy link

riker09 commented Dec 2, 2014

I noticed that when I start to type, every field returned by autocomplete/product/json/ is used for autocompletion. So a search for min_price or simple results in some matches simply because these field names / values are present in the json string. Although these fields and values may be required for a (harder) better, faster (stronger) display of the results they shouldn't be used for matching.

@jreinke
Copy link
Owner

jreinke commented Dec 2, 2014

How do you see that all fields are used as soon as you start typing something?
As far as I can see, only name field is used thanks to the datum tokenizer used: Bloodhound.tokenizers.obj.whitespace('name')
This means that name field is split into tokens with whitespace separator.

@riker09
Copy link
Author

riker09 commented Dec 2, 2014

I'll provide an example screenshot tomorrow. But when I searched for
"simple" the autocompleter returned all three simple products in my local
demo store.
Am 02.12.2014 17:24 schrieb "Johann Reinke" notifications@github.com:

How do you see that all fields are used as soon as you start typing
something?
As far as I can see, only name field is used thanks to the datum
tokenizer used: Bloodhound.tokenizers.obj.whitespace('name')
This means that name field is split into tokens with whitespace separator.


Reply to this email directly or view it on GitHub
#3 (comment)
.

@riker09
Copy link
Author

riker09 commented Dec 3, 2014

Here is the promised screenshot. Please note that I've disabled localStorage in the settings, but that shouldn't make any difference.

magento-autocomplete

As you can see I simply searched for the term simple and as a result I got all three simple products that are currently available in my demo shop. After reading the documentation of bloodhound I do not see why these results are shown. The code your module generates is as following:

<script type="text/javascript">
//<![CDATA[
// Bypass default autocomplete
Ajax.Autocompleter.prototype.getUpdatedChoices = function() {
    return false;
};

jQuery('#search').removeClass('required-entry');

// init some useful variables
var priceFormat = {"pattern":"%s\u00a0\u20ac","precision":2,"requiredPrecision":2,"decimalSymbol":",","groupSymbol":".","groupLength":3,"integerRequired":1};
var baseUrl = 'http://mage1910.localhost/';
var baseUrlMedia = 'http://mage1910.localhost/media/catalog/product';
var imgPlaceholder = 'http://mage1910.localhost/media/catalog/product/cache/1/small_image/100x100/9df78eab33525d08d6e5fb8d27136e95/images/catalog/product/placeholder/small_image.jpg';

// constructs the suggestion engine
var engine = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
        remote: { url: 'http://mage1910.localhost/autocomplete/product/json/' },
        limit: 5,
    ttl: 86400000 // milliseconds
});

// kicks off the loading/processing of `local` and `prefetch`
engine.initialize();

jQuery('#search').typeahead({
    hint: true,
    highlight: true,
    minLength: 1}, {
    name: 'products',
    displayKey: 'name',
    // `ttAdapter` wraps the suggestion engine in an adapter that
    // is compatible with the typeahead jQuery plugin
    source: engine.ttAdapter(),
    templates: {
        empty: '<div class="empty">' +
                   'No Result' +
               '</div>',
        suggestion: function(product) {
            var img = imgPlaceholder;
            if (product.thumbnail && product.thumbnail != 'no_selection') {
                img = baseUrlMedia + product.thumbnail;
            }
            return '<a href="' + baseUrl + product.url_path + '">' +
                        '<div class="image">' +
                            '<img src="' + img + '">' +
                        '</div>' +
                        '<div class="info">' +
                            '<span class="name">' + product.name + '</span>' +
                            '<div class="price-box">' + formatSuggestionPrice(product, priceFormat) + '</div>' +
                        '</div>' +
                        '<div class="clearer"><!-- --></div>' +
                    '</a>';
        }
    }
});

jQuery('#search').bind('typeahead:selected', function(obj, product, name) {
    window.location.href = baseUrl + product.url_path;
});

function formatSuggestionPrice(product, priceFormat) {
    var price = '';
    switch (product.type_id) {
        case 'grouped':
        case 'configurable':
        case 'bundle':
            price = '<p class="minimal-price">' +
                        '<span class="price-label">Ab:&nbsp;</span>' +
                        '<span class="price">' + formatCurrency(product.min_price, priceFormat, false) + '</span>' +
                    '</p>';
            break;
        default:
            price = '<span class="price">' +
                        formatCurrency(product.price, priceFormat, false) +
                    '</span>';
    }

    return price;
}
//]]>
</script>

@awwea
Copy link

awwea commented Jan 21, 2015

Hello guys, realy nice and useful extension.
I need to know where it shoud be changed to print the price included tax, please.

@winkelsdorf
Copy link

@riker09 Is this report still valid? I cannot confirm this on a fresh installation. Bloodhound.tokenizers works as expected..

@awwea This extension expects prices incl. taxes in magento from what I can see. Adding code for reading tax information for each product and add it to the collection seems to be a lot of work.

@winkelsdorf
Copy link

@riker09 Think I found the bug during my tests related to #2.

@jreinke is using Bloodhound a bit wrong. Prefetch & Remote serve a different purpose. If remote is triggered, the result set is actually treated as a real 'result set' - so everything coming from the url remote is a result.

I am trying to implement a correct ajax request handling now which prefetches the most current or best selling products as initial json and the real search requests on demand by fetching from db. This should solve this.

@winkelsdorf
Copy link

Fixed in preview fork winkelsdorf@f6b4df8

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

No branches or pull requests

4 participants