Solr - When Save and Update an Index In Form Data Entry scenarios - solr

I have a web form from which I want to save the data from the very first page to an index by using this sample code below.
Startup.Init<SomeModel>("http://localhost:8983/solr/somemodels");
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Quote>>();
solr.Add(new SomeModel() {Id=1001; Content="Some Content"});
solr.Commit();
On the very last page, the user is given a chance to change/update his entries on the form. Should I also use this line of code?
solr.Add(new SomeModel() {Id=1001; Content="New Content"});
Also, is this a good practice - having indexes updated in this fashion?

You can consider the below things.
Is there any chance that user does something in the first page and drops off in before reaching the last page?
If this is valid scenario and data loss is not acceptable, you should
save the data.
If you only want to save the data when use reaches at the last page, then you should do the below.
You should save the data which you want to be saved between pages. At the last page, you save it too SOLR.
Hope you are also using some backend data source to save the data and solr for search use cases. In this case, it is advisable to update one doc once per operation.
In case of Cassandra as backend. there are chances for tombstone when you update a document multiple times.

Related

AngularJS dynamic table - RESTfull data

I have a big data portion that I would like to post in a table. However, the data should be sorted and paginated. I know I am able to pass the whole data to the client at once and then paginate it using angular, but this will be too slow. I prefer to pass the data page-by-page, so one the client want to open a page from a table to load the data for it.
Up until now I have created an API that returns me the data that I need, based on the page number and the number of rows on the page. However, I don't know how to use it with AngularJS.
Can you please help me?
It looks like a backend problem. If you are using a standard restful backend, use the limit/skip parameters, you can encapsulate into a paginate.
Example:
localhost:1337/dataTable?skip=0&limit=100
localhost:1337/dataTable?skip=100&limit=100
localhost:1337/dataTable?skip=200&limit=100
...
On the frontend use a table object like ng-Table, and use the pages to keep track of the offset, the page number and the total items available.
skip = (pagNum - 1 * pageSize)
limit = pageSize
Make your backend return you the page you want plus the available dataNumber so you can build the pages controller.
Documentation for skip/limit on sails
http://sailsjs.org/documentation/reference/waterline-orm/queries/limit
http://sailsjs.org/documentation/reference/waterline-orm/queries/skip
Best approach is to keep track of the limit and offset in your controller. Then when user selects new page (offset) or changes items per page (limit), update the corresponding values and use them to make a new http request.
You could call a function on ng-change of a dropdown and that drop down would contain values of page number and number of records to fetch. Or you can provide two text boxes one for page number other for number of records and keep a button and on its ng-click event that will take value of those text boxes and post to your server and bring back data based on new values in text boxes

To search a grid for a value in extjs

var record = store.findRecord('InterviewerID', id);
This line searches for the record visible on the grid.
If the record is present in the next page(Pagination) then it does not search.
Could you please provide a way to search the whole store?
The findBy approach still would not work.
Your store will only contain a single page of data returned from the server. To search across pages you would need to search server side and determine which page of data it exists on. Once you know which page of data the searched term exists on, you could load that page of data into your store.

Is there a way to quickly add a new row of fields on a visulforce page?

I am trying to create a incident log in safesfore. The key aspect is that everything can be added on the same page reducing the amount of clicks that have to be made. There are 6 fields i have created:
Date Opened, Date closed, incident, reported to, reported by and notes.
I was wondering if there is a way to create an "add new" button that will create another row of the fields i have just lised. The idea being that the page does not refresh it is all done in real time.
Many thanks
You'll need a custom Visualforce page implementation.
There are 2 ways to do it
1) Building a list of records on apex and iterate over that list displaying the fields on the front end (vf page apex:repeat)-- Then when the button "add new" is clicked you'll append an empty record to the list and re-render the apex:repeat to reflect the changes.
This is good because you don't need a lot of boilerplate code since the records with be binded with the backend. However, the rerendering can lead to some performance issues in my experience.
2) Build a custom Javascript implementation, where you have an in memory collection and using DOM manipulation add/remove rows of the list. When the user saves the data from memory must be sent using JSON and a VF Remoting method can perform the JSON parsing and saving the rows.
Both are valid, the first is good to avoid boilerplate but the second is much faster (but you need to write some boilerplate).

Using google search api cursor in angular js app to get all results for google patent search

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?

asp mvc, best solution to store user input data before it will be saved to database

for example i've got a form with some input fields(every form and it's inputs with validation rules are stored in database).
Every input got it's own OnChange() which posts json (i.e. new value, input element name, ...) to controller for validation, if validation passes the new value must be saved somewhere until user clicks submit button, which will save all data to database table.
And here i'd like to ask, what this special place between ui and database can be ?
p.s.
also if user closes browser/form the next time he'll come back i need to ask him if he would like to start from an empty form or fill form with values he previously entered there.
Thank You !
Cookies or intermediary database table would work for this case.
for an intermediary database like that, you could use something like MongoDB, it is really easy to get it started, you just work with the classes you have, don't need to setup any schema, you just save the objects
http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial
If you are submitting the entire form at the end, why can't you just store the values at that time? Is this a multi-page form(s)? Why not allow the database records to be partially filled? You could always add a bit column to mark the record as complete or incomplete. This would be much simpler than duplicating your table structure.

Resources