How to show facet values on the front end in Hybris? - solr

I have added a brand attribute of String type in the ProductModel through item.xml.
I need to create a facet for brand. I have two brands - Sony and Canon.
After creating the facet, I'm able to see "Shop by Brand" on the UI, but I'm not able to find Sony or Canon under it.
The impexes I used are:
INSERT_UPDATE SolrIndexedProperty;solrIndexedType(identifier) [unique=true];name[unique=true];type(code);sortableType(code);currency[default=false];localized[default=false];multiValue[default=false];facet[default=true];facetType(code);facetSort(code);priority;visible;useForSpellchecking[default=false];useForAutocomplete[default=false];fieldValueProvider;valueProviderParameter;facetDisplayNameProvider;customFacetSortProvider;topValuesProvider;rangeSets(name)
;$solrIndexedType;brand;string;;;;;;Refine;Alpha;;true;true;true;springELValueProvider;
INSERT_UPDATE SolrSearchQueryProperty; indexedProperty(name, solrIndexedType(identifier))[unique = true]; searchQueryTemplate(name, indexedType(identifier))[unique = true][default = DEFAULT:$solrIndexedType]; facet[default = true]; facetType(code); includeInResponse[default = true]; facetDisplayNameProvider;facetSortProvider;facetTopValuesProvider
; brand:$solrIndexedType ; ; ; ; ;
Can someone please point out what am I missing?

To make brand attribute as to available as facet need to follow below steps:
Index brand attribute to SOLR via value provider by creating
SolrIndexedProperty and associating it with value provider
After indexing ensure that data being sent to SOLR for corresposding products
Next steps is to do facet settings in Bakcoffice (or this can also be done via solr.impex while creating SolrIndexedProperty header impex for custom brand attribute)
Edit that attribute in Backoffice facet configuration and go to "Facet Settings" tab which will enable us to define facet for custom (brand) attribute, which can be used to filter results based on facet value in PLP or SLP. Make "Facet" to 'TRUE'
Or this can be handle via impex by setting facet[default=true]
Select facet type to be 'Single Select' or 'Multi Select' via facetType(code)
Re-Index Solr and changes should get reflect upon Search or PLP

Related

Ordering the solr search results based on the indexed fields

I have to order the search results from solr based on some fields which are already indexed.
My current api request is like this without sorting.
http://127.0.0.1:8000/api/v1/search/facets/?page=1&gender=Male&age__gte=19
And it gives the search results based on the indexed order. But I have to reorder this results based on the filed 'last_login' which is already indexed DateTimeField.
Here is my viewset
class ProfileSearchView(FacetMixin, HaystackViewSet):
index_models = [Profile]
serializer_class = ProfileSearchSerializer
pagination_class = PageNumberPagination
facet_serializer_class = ProfileFacetSerializer
filter_backends = [HaystackFilter]
facet_filter_backends = [HaystackFilter, HaystackFacetFilter]
def get_queryset(self, index_models=None):
if not index_models:
index_models = []
queryset = super(ProfileSearchView, self).get_queryset(index_models)
queryset = queryset.order_by('-created_at')
return queryset`
Here I have changed the default search order by 'created_at' value. But for the next request I have order based on the 'last_login' value. I have added a new parameter in my request like this
http://127.0.0.1:8000/api/v1/search/facets/?page=1&gender=Male&age__gte=19&sort='last_login'
but it gives me an error
SolrError: Solr responded with an error (HTTP 400): [Reason: undefined field sort]
How can I achieve this ordering possible? Please help me with a solution.
The URL you provided http://127.0.0.1:8000/api/v1/search/facets/ is not direct SOLR URL. It must be your middle-ware. Since you have tried the query directly against Solr and it works, the problem must be somewhere in middle-ware layer.
Try to print or monitor or check logs to see what URL the midde-ware actually generates and compare it to the valid URL you know works.

How to get users from Active Directory using Unboundid LDAP SDK?

I need to get users from Active Directory.
According to many places include MSDN
https://msdn.microsoft.com/en-us/library/ms677643%28v=vs.85%29.aspx
the correct query is this (&(objectClass=user)(objectCategory=person)).
Unfortunately, I was not able to create the query using Unboundid filters.
I have created the following filters:
Filter categoryFilter = Filter.createEqualityFilter("objectCategory","Person");
Filter objectFilter = Filter.createEqualityFilter("objectClass","user");
Filter searchFilter = Filter.createANDFilter(objectFilter, categoryFilter);
It does not return results.
When I looked into objectCategory of LDAP object I have found that it looks like the following:
CN=Person,CN=Schema,CN=Configuration,DC=…,DC=com
Therefore I have changed categoryFilter to the following:
Filter categoryFilter = Filter.createSubstringFilter("objectCategory", null, new String[]{"Person"}, null);
Unfortunately, I still do not get results.
Then I used the categoryFilter with the full objectCategory name:
Filter categoryFilter = Filter.createEqualityFilter("objectCategory","CN=Person,CN=Schema,CN=Configuration,DC=…,DC=com");
Only in the last case I get results.
How to make the filter more generic?
How to obtain the full objectCategory name from Active Directory?
I need to obtain CN=Person,CN=Schema,CN=Configuration,DC=…,DC=com for any Active Directory while I know that the objectCategory is Person.
Do you know other way to create filters for the query (&(objectClass=user)(objectCategory=person))?
Solution
(not mine therefore do not want to put in the answer)
I have created filter using the following string (sAMAccountType=805306368) and it works perfect:
Filter searchFilter = Filter.create("(sAMAccountType=805306368)");
Source: http://ldapwiki.com/wiki/Active%20Directory%20User%20Related%20Searches#section-Active+Directory+User+Related+Searches-AllUsers

How to upload pdf and update field within one request in solr

All:
I am new to solr and solrj. What I want to do right now is uploading pdf file to solr and set customized field such as last_modified field at same time.
But I keep encounter the error such as " multiple values encountered for non multiValued field last_modified", I use solrj to upload pdf and set the last_modified field like
ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/extract");
up.setParam("literal.last_modified", "2011-05-19T09:00:00Z");
I guess the error is due to when solr extract the pdf, it uses some meta data as last_modified field value as well so that my custmized last_modified value leads to a multivalue error, but I wonder how to replace the meta data with my custmized data?
Thanks
/update/extract is defined in solrconfig.xml for your core. You can see the configuration there and modify it to match it to your particular scenario. The Reference Guide lists the options.
In your particular scenario, something look strange. The parameter that seems to be relevant is literalsOverride but it is true by default. Perhaps, you are setting it to false somewhere.
You can also try explicitly map Tika's last update field to some different name.
I would enable catch-all (dynamicField *) as store=true and see what is being captured. Then you can play with the parameters until you are happy. You don't have to restart Solr, just reload the core from the Admin UI.
I have faced similar issue, where I need to fetch one dynamic field value and do some operation then update it. I use below code to achieve this.
First check for that field is it exist or not. Try using below code may be it will help you.
Map<String, String> partialUpdate = new HashMap<String, String>();
if(alreadyPresent)
{
partialUpdate.put("set", value);
}else
{
partialUpdate.put("add", value);
}
doc.addField("projectId", projectId); // unique id for solrdoc
doc.addField(keys[0], partialUpdate);
docs.add(doc);
solrServer.add(docs);
solrServer.commit();

What is the variable that refers to the number of likes on sharepoint 2013?

I want to write a request on the search result request webpart. My request should enables me to retrieve all documents that have the biggest number of likes. There is no variable for the number of likes proposed on the drop list while writing a request , that why I decided to set a refinableInt00 variable and give it the value : LikesCount but it doesn't work? it means that LikesCount doesn't exist as a variable on sharepoint so what is the variable on sharepoint that would enable me to have the number of likes?
You can get the number of likes using the listitem property "Number of Likes"
This is a code from a Sample console application
using (SPSite site=new SPSite("your site URL"))
{
using (SPWeb web=site.OpenWeb())
{
SPList list = web.Lists["Your List Name"];
foreach (SPListItem item in list.Items)
{
//Print the number of likes
Console.WriteLine(item["Number of Likes"].ToString());
}
}
}
I know this is old but I had the same question. The problem is the LikesCount property does not default to Sortable. To fix this:
-Open up Central Administration
-Go to Search Service Application
-Click on Search Schema
-Locate the "LikesCount" property and click edit
-Scroll down to Sortable and change to Yes
-Run a full crawl on your content source
Ratings for list must be enable.
List -> List settings -> Rating settings ->
Allow items in this list to be rated?
yes ? no
and
Which voting/rating experience you would like to enable for this list?
Likes ? Star Ratings
After that you can access likes by "Number of Likes" field name "LikesCount".
"Number of Ratings" field name "RatingCount"

Salesforce: Picklist(multiple) with dynamic value

I have add custom field to Account with picklist(multiple) in Salesforce. But the values of picklist should be dynamically generated from other object. If not, is it possible to push values in picklist from native app(which is written in ruby)?
I dont think the standard controller supports dynamically adding the possible picklist (select list) values.
What you could do is add a text field instead of a picklist and create a custom page with visualforce. Use the standard controller with an extension for your code.
Create a new custom object for holding picklist values for a field (could be reused for other fields). Populate it with the possible picklist values.
In the page controller, load the values for that field.
In visualforce, display a picklist for the custom field and load the values from the controller.
Add an extra input field for manual insertion if desired.
On save, insert the value of the picklist (or input box) into the custom field.
A more detailed guide can be found here
Why dont't you use a normal SelectOption List in Apex?
public List<SelectOption> getMyPicklist()
{
List<SelectOption> options = new List<SelectOption>();
List<Account> acc = [ Select Id, Name From Account Limit 10 ];
for(Account a : acc){
options.add(new SelectOption(a.Id,a.Name));
}
return options;
}
I had to update picklist with values from my database (and not from some visualforce page). So I authenticated account using Databasedotcom gem and it provides nice Api to iteract with Salesforce Objects (both Standard and Custom).
client.authenticate :token => "my-oauth-token", :instance_url => "http://na1.salesforce.com" #=> "my-oauth-token"
account = client.materialize("Account")
account_to_be_updated = account.find(account_id) # here account is same as Instance of Activerecord
account_to_be_updated.my_picklist = [value1; value2; value3; value4]
account_to_be_updated.save

Resources