Solr attributes not giving Expected results

944 views Asked by At

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);
     }
2

There are 2 answers

0
Sergey Khudyakov On BEST ANSWER

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 use DefaultSolrProductSearchService.searchAgain(SolrSearchQueryData, PageableData) service method for complex filtering.

0
AudioBubble On

In general you should extend this via the Converter/Populators, rather than via the Service.

If you do not want these products in the suggestions but you do want them in results then what you have attempted to code above is not correct. The code above would seem to be attempting to filter them from all results.