I added a new Attributes into my Solr.impex based on this attributes sale product should not be listed in search suggestion as well as search result, I did the following changes but unable to get expected results :--
INSERT_UPDATE SolrIndexedProperty;solrIndexedType(identifier) unique=true];name[unique=true];type(code);sortableType(code);currency[default=false];localized[default=false];multiValue[default=false];useForSpellchecking[default=false];useForAutocomplete[default=false];fieldValueProvider;valueProviderParameter
;$solrIndexedType; sale ;boolean; ; ; ; ; ; ;
And override the textSearch method Like as follows:
public class DefaultCustomSolrProductSearchService <ITEM> extends DefaultSolrProductSearchService
{
@Override
public ProductCategorySearchPageData<SolrSearchQueryData, ITEM, CategoryModel> textSearch(
String text, PageableData pageableData) {
SolrSearchQueryData searchQueryData = createSearchQueryData();
searchQueryData.setFreeTextSearch(text);
List<SolrSearchQueryTermData> searchTermList = new ArrayList<SolrSearchQueryTermData>();
SolrSearchQueryTermData searchTerm = new SolrSearchQueryTermData();
searchTerm.setKey("sale");
searchTerm.setValue(Boolean.FALSE.toString());
searchTermList.add(searchTerm);
searchQueryData.setFilterTerms(searchTermList);
return super.doSearch(searchQueryData, pageableData);
}
Looks like the main problem is that your
sale
field is not a facet, and consequently it is not added to resulting SOLR search query.Also, as Stretch already said, your code will filter out sale products not only from suggestions result, but also from regular text search result. I don't think that this is what you want to achieve.
Since
SearchPageController
uses the same service method for both text search and autocomplete suggestions, possible solution to this might be introducing a separate facade (or maybe a controller helper method is enough) for suggestions. And you can also useDefaultSolrProductSearchService.searchAgain(SolrSearchQueryData, PageableData)
service method for complex filtering.