I have a web application that uses SOLR as backend search service.
All requests that control searches are GET requests: user does something (type something, choose a page size, a sort critera) and, after pressing the search button, a corresponding servlet on the web app calls SOLR.
Now, the parameters sent to my servlet are exposed in the browser address bar; this is good because
1) each page on the webapp can be stored as permalink
2) the search can be controlled by changing directly the URL
On top of that, for a specific parameter, the page size, I would like to impose some constraint. I mean: if the select menu on the web app proposes 3 choices (5,10,15) I don't want other values.
Now, I know I can do that in my servlet but I was wondering if it is possible on SOLR side too...local params? don't know.
Briefly: the "rows" parameters on SOLR must be 5,10 or 20: if a value > 20 comes then 20 is applied.
Within Solr SearchHandlers you can predefine some configuration settings as outlined in the Configuration section. This allows you to set the following parameter behaviors
defaults - provides default param values that will be used if the param does not have a value specified at request time.
appends - provides param values that will be used in addition to any values specified at request time (or as defaults.
invariants - provides param values that will be used in spite of any values provided at request time. They are a way of letting the Solr maintainer lock down the options available to Solr clients. Any params values specified here are used regardless of what values may be specified in either the query, the "defaults", or the "appends" params.
However, these three options, do not provide for the specific behavior of limiting the rows value to 20 like you are seeking. I believe the only way to limit this within Solr would be to create a custom Request Handler and plug that into Solr. The article - Developing a Request Handler for Solr provides a good overview of the steps needed to create you own Request Handler.
Related
For a weblog I am trying to get the top 10 popular posts from for example the last month. I figured I'd get the data out of Matomo, as that's already tracking visits and has an API. I've never used this API before though, so I've been reading the documentation and trying out some things. I am able to get data from the API using the Actions.getPageUrls method. However, when I try to filter using segment=^http://example.org/post I still get data from other URL's. It looks like it filters on session and gives back all data from the sessions that have at least 1 page that conforms to the filter.
The full URL I'm using is: http://example.org/matomo/index.php?&module=API&token_auth=12345&method=Actions.getPageUrls&format=json&idSite=1&period=month&date=today&expanded=1&segment=pageUrl%3D%5Ehttp%253A%252F%252Fexample.org%252Fpost. I've also tried with less and no URL encoding for the segment, but that doesn't seem to make a difference. If I use a URL that doesn't exist I get an empty array returned.
Am I doing something wrong? Is there a different way to only get the top pages with a URL starting with http://example.org/post? Or do I have to sift through the data myself to only get the pages I want?
I am using Matomo version 3.13.5.
I figured it out. There is no need to use segment. This can be achieved using the flat, filter_column and filter_pattern parameters.
Setting flat=1 will make it so all pages are returned in a single array, instead of hierarchically.
With filter_column and filter_pattern I can filter the results.
The URL I use now is: http://example.org/matomo/index.php?&module=API&token_auth=12345&method=Actions.getPageUrls&format=json&idSite=1&period=month&date=today&flat=1&filter_column=label&filter_pattern=%5E%2Fpost%2F. This does exactly what I want.
The unencoded pattern is ^/post/, so this will filter out any page that does not start with /post/.
So, I've been attempting to gather picklist dependencies per Opportunity record type for my lightning components. I have been able to retrieve Standard Field dependencies by RecordType, but it the Tooling API will not return the custom field dependencies. Standard calls and queries will not work either, as they state that the field has no controlling value or dependency.
Given this information I suspected that there was a table that is hidden somewhere that contains the keys for the RecordType and FieldDefinition, hopefully with a nested Metadata object.
I found an Id in one of the parameters in the setup menu for a Record Type and Id.getSObjectType() on it. The table name is CustomFieldDefinition. However, it is not accessible via SOQL or the Tooling API.
Has anyone accessed this table? Or has anyone been able to retrieve the field-record type picklist dependencies on custom fields AND standard fields?Tooling API ResponseDebug Log with SObject Name
I think you're doing it wrong.
"Controlling field" would be another picklist or a checkbox for example, something you change during same edit action. If you have dependency to record type - in that sense it's not a controlling field. Sure, you change record type and picklist changes - but really everything would change, it should be a different page layout (different fields shown, marked readonly/required etc). There's a reason that record type change is not done on normal edit screen, you do it by clicking special link on detail view and then everything "explodes".
Have a look at "User Interface API" - set of tools meant to help your custom app (mobile? desktop?) steal recreate a normal page layout. This one might be especially useful: https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_resources_picklist_values_collection.htm
There's even a Trailhead: https://trailhead.salesforce.com/en/content/learn/modules/user-interface-api (skim through whole set but especially read last module)
And since you mentioned Lightning Components - are you aware of these ready tools:
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.reference_ui_api
getPicklistValuesByRecordType
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.reference_generate_record_input_create
or maybe you don't have to code it all and stuff like <lightning-record-edit-form> with recordtypeid passed to it will solve all your problems
Have a look, if I didn't give you a working solution then at least you have some keywords to Google around. If you're still stuck - try to post a code sample as new question?
Our Solr is configured to return ALL results if no valid search parameters are passed in. For example:
http://localhost:8983/solr/collection1/select?rows=1&title=bar is a valid search (title is a valid field) and it returns the proper number of results (1 out of many results). But... http://localhost:8983/solr/collection1/select?rows=1&foo=bar returns one out of the entire collection (foo is not a valid field).
I read that there is a way to configure Solr to return NO results by default (instead of all). It said "adjust the requestHandler config to return all results by default" (which I assume means there is a way to return none by default) but I cannot find anything online about how to actually do this.
The reason we want this is because we're implementing a blacklist of fields that we don't want the user to search on, but by doing this, it allows all other fields through and we'd like those to return no results (or even better - an error saying the field is invalid).
Solr is being called through our API that we wrote, so even if we could add on a parameter to each call to make it return no results by default (noResultsIfNoValidSearch=true or something), that would work.
So, any ideas on how to configure Solr to return NO results by default? Thanks!
Add echoParams=all into your query to see everything that the request has, coming from all configuration sources.
Most likely you define q=*:* somewhere in your configuration, that's what causing returning everything. Remove that and you should get nothing.
If you are using eDixMas, you can look into uf parameter which allows to restrict the fields users are allowed to query.
To allow all fields except title, use uf=*-title
The easiest thing that comes to mind is to set the rows parameter to 0 in your API or config, depending on your requirements.
I want to make a search into google patent using the following URL which is obsolete
https://ajax.googleapis.com/ajax/services/search/patent?v=1.0&q=thumb%20wrestling%20apparatus&userip=192.168.1.102
It gives me limited number of records per page.
But at the end of the JSON it also returns the cursor which has start and label keys. So my question is that how can I use that cursor to show all the records in my search. Like if there are 8 pages and each page contains 4 records so I want to show all 32 records on my UI.
How can I achieve that?
And second question that is there REST APi for google patent search? If yes then how can I search the patent using REST API and how can I get all the records on one page?
It looks like the API is restricted to a maximum of 8 results per request (you can increase your current 4 results to 8 by using the query param rsz=8.
So I guess the only way to get all results is by performing multiple requests. So if the current page info data is...
"pages":[
{"start":"0","label":1},
{"start":"8","label":2},
{"start":"16","label":3},
{"start":"24","label":4},
{"start":"32","label":5}
]
You would make 5 requests chaining the start param start=0, start=8 ... and so on, extracting the results and pushing to an array store. If you're not already I recommend using something like Restangular, as it would make this process much easier.
Depending on how your UI is set out, it would be nice maybe to do this with some lazy loading as the user is scrolling through the list?
We are making a gamification component for our forum, which is being developed in Django. We would like users to receive badges right away after achieving certain goals. However, we are concerned about the amount of database queries that would be made. For example, take a badge that is given if a post gets a certain amount of views. If the condition for the badge is checked every time the post is viewed, that would be a lot of queries. Is our only other option to check at certain intervals or another event, like the user viewing their profile? That would be less optimal from the user perspective, because of the delay.
There is a different approach that may suit you, using webserver logging and post-processing that log to generate stats. I have used it in Apache with some projects that required pageview hit counts. A similar configuration for other webservers would work the same.
I use django.contrib.contentypes to write down the Content Type ID and Object ID of the object accessed on this example, but you can, of course, log anything you want.
So, in your Apache virtualhost conf file, adding a LogFormat directive like this:
LogFormat "%{X-H-CID}o|%{X-H-OID}o" hitcounter
And then attaching it to a CustomLog:
CustomLog path/to/your/logfile.log hitcounter
This will enable Apache to write down to the logfile the following HTTP headers: X-H-CID and X-H-OID, which represent the ContentType ID and Object ID of the object being hit. From a view, you may add the headers to the HttpResponse:
ctxt = RequestContext(request)
rendered = render_to_string(template, ctxt)
http_res = HttpResponse(rendered)
http_res['X-H-CID'] = content_type_id
http_res['X-H-OID'] = object_id
Replace content_type_id and object_id with your real object props.
This example should write a line like:
16|4353
where 16 is the Content Type ID and 4353 the Object ID. Finally, you can schedule a django custom command to process that logfile and perform the needed actions.