I have a view like
function (doc, meta)
{
if(doc.Tenant)
{
emit([doc.Tenant.Id,doc.Tenant.User.Name],doc);
}
}
In this view I want all the value belongs to Tenant.Id == 1 and User.Name where Contains "a"
I can search this in my C# by collecting all the Tenant data belongs to particular Tenant Id.
But I have million of data for each Tenant. So need to check this in the server side itself.
Is this possible to search.
I'm guessing that you want to be able to change which letter you are searching for in the string, unfortunately couchbase isn't going to be the best thing for this type of query.
If it will always be the letter 'a' that you want to search for then you could do a map like this and then query on the id.
function (doc, meta) {
if(doc.Tenant) {
var name = doc.Tenant.User.Name.toLowerCase();
if(name.indexOf("a") > -1) {
emit(doc.Tenant.Id,null);
}
}
}
If however you want to be able to dynamically change which letter or even substring you want to search for in the name then you want to consider something like elasticsearch (great for text searching). Couchbase has an elasticsearch transport plugin that will automatically replicate to your elasticsearch node(s).
Here is a presentation on ES and Couchbase
http://www.slideshare.net/Couchbase/using-elasticsearch-and-couchbase-together-to-build-large-scale-applications
The documentation for installation and getting started with the ES plugin
http://docs.couchbase.com/couchbase-elastic-search/
And a cool tutorial detailing how to add a GUI on top of your ES data for easy filtering.
http://blog.jeroenreijn.com/2013/07/visitor-analysis-with-couchbase-elasticsearch.html
Related
Let say I have an app where I want to give someone the weather in a city.
The first scene has a prompt: "What city would you like the weather of?"
I then have to collect a slot/parameter called conv.param.city: and then use it in my node webhook which is:
const { conversation } = require('#assistant/conversation');
const functions = require('firebase-functions');
const app = conversation();
app.handle('schedule', (conv, {location}) => {
let temperature = callApi(location);// this part doesn't matter right now
**conv.add(`You want to know the weather in ${location}`);
conv.close(`The weather in ${location} is ${temperature}`);
});
exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app);
From what I can tell, you can only take in parameters/slots that are predefined by types/intents. I cannot make a list of all cities that exist to train with. How can I basically say: Whatever the user says at this point, make that word into this variable.
How can i do this with the Google Actions SDK?
You can accomplish this by setting your intent parameter type to be free text (here's an example from one of the sample repos).
freeText: {}
If you apply this type to an intent parameter, you can use the training phrases to provide the necessary context on where in the phrase that "word" should be matched (example from the same repo).
I cannot make a list of all cities that exist to train with.
Another option exists if your API can return the set of locations supported. You can also use runtime type overrides to dynamically generate the type from the list of list of locations the API provides. This will be more accurate, but is dependent on what your data source looks like.
I have a scenario where I have to import data (millions of records) from multiple sources and save it in a database. A user should get results in under 2-3 seconds when they try to search for any information related to that data.
For this, I designed an architecture where I used golang to import data from multiple sources and pushed data in AWS SQS. I've created a lambda function which triggers when AWS SQS has some data. This lambda function then pushes data in AWS Elastic Search. I've created a Rest API using which I give results to the user.
I use CRON to do this importing work every morning. Now my problem is if a new batch of data comes I want to delete the existing data and replace all of them with the new data.
I'm stuck at how I can achieve this deleting and adding new data part.
I thought of creating a temporary index and then replacing it with the original index. But the problem is I do not know when importing has ended and can make this index switch.
The concept you're after is an index alias. The basic workflow would be:
Import today's data into an index with my-index-2019-09-16 (for example).
Make sure the import is complete and worked correctly.
Point the alias to the new index (it's an atomic switch between the indices):
POST /_aliases
{
"actions" : [
{ "remove" : { "index" : "my-index-2019-09-15", "alias" : "my-index" } },
{ "add" : { "index" : "my-index-2019-09-16", "alias" : "my-index" } }
]
}
Delete the old index.
You will double the disk space during the import process, but otherwise this should work without any issues and you only delete data once it has a proper replacement.
I am trying to figure out how to calculate, then store the layout delta for a rendering programatically. The situation I'm in is that I have a rendering defined on my standard value. It's datasource is empty. I then have a process that creates an item based on that template, but I need to set the datasource on the rendering.
By default, the __Renderings field on the new item is blank (as is expected). So far, I've been able to get a RenderingReference to my rendering, detect that the datasource is blank, but I cannot for the life of me figure out how to set the datasource then store the correct delta in the __Renderings field on my item.
So far I have:
foreach (var device in new DeviceRecords(database).GetAll())
{
foreach (var rendering in myItem.Visualization.GetRenderings(device, false).Where(r => r.RenderingID == renderingId)
{
if (rendering.Settings.DataSource.IsNullOrEmpty())
{
var dataSourceItem = datasourceFolder.Add("Datasource name", dataSourceTemplate);
rendering.Settings.DataSource = dataSourceItem.ID.ToString();
using (new EditingContext(myItem)){
myItem[FieldIDs.LayoutField] == //????
}
}
}
}
My guess is I need to somehow invoke something in XmlDelta, but it looks like all of those methods want some Xml to work with, when all I have is the rendering item.
I wrote some code a while back that tried to extract data source information from Sitecore's XML deltas. I never tried updating it though, but this may work for you.
The class I used was Sitecore.Layouts.LayoutDefinition which is able to parse the XML and if I remember correctly it deals with the business of working out what the correct set of page controls is by combining the delta with the underlying template data. You can construct it like so:
string xml = LayoutField.GetFieldValue(item.Fields["__Renderings"]);
LayoutDefinition ld = LayoutDefinition.Parse(xml);
DeviceDefinition deviceDef = ld.GetDevice(deviceID);
foreach(RenderingDefinition renderingDef in deviceDef.GetRenderings(renderingID))
{
// do stuff with renderingDef.Datasource
}
So I think you can then use the API that LayoutDefinition, DeviceDefinition and RenderingDefinition provides to access the data. There's a bit more info on how I used this in the processImages() function in this blog post: https://jermdavis.wordpress.com/2014/05/19/custom-sitemap-filespart-three/
I think the missing step you're after is that you can modify the data this object stores (eg to set a data source for a particular rendering) and then use the ToXml() method to get back the revised data to store into your Renderings field?
You may be able to find more information by using something like Reflector or DotPeek to look inside the code for how something like the Layout Details dialog box modifies this data in the Sitecore UI.
-- Edited to add --
I did a bit more digging on this topic as I was interested in how to save the data again correctly. I wrote up what I discovered here: https://jermdavis.wordpress.com/2015/07/20/editing-layout-details/
I am working on register local search terms in Sitecore DMS. I took help from the following blog. First of all I registered a Search page Event with named "Search".
protected void RegisterSearchPageEvent(string searchQuery)
{
if (!Tracker.IsActive || Tracker.Visitor == null || Tracker.Visitor.CurrentVisit == null)
return;
var page = Tracker.Visitor.CurrentVisit.CurrentPage;
if (Tracker.Visitor.CurrentVisit.PreviousPage != null)
page = Tracker.Visitor.CurrentVisit.PreviousPage;
page.Register(new PageEventData("Search")
{
Data = searchQuery,
DataKey = searchQuery.ToLowerInvariant(),
Text = searchQuery
});
}
I also defined the page event “Search” in Sitecore. Now to display the Report in Executive Dashboard I went under the "Site Search" but it does not display anything.
I configured the .config file located here:
\sitecore\shell\Applications\Reports\Dashboard\Configuration.config
Here there is a setting called “MinimumVisitsFilter“. I set it from 50 to 5 and also entered the search keywords - more than 50 times. The main point is here is that the above code is inserting the keyword into the Analytics database. Is there any SQL Query problem for Executive Dashboard?
Even with the MinimumVisitsFilter set to 5, you still need to generate 5 unique visits to start seeing any data. On your local dev environment you could probably set this one as low as 1 or even 0 - but I would not recommend you did this on the live environment.
Also make sure all the basics are in place; Analytics is active (Sitecore.Analytics.config), the database is set up and so on.
I followed the same post when registering local search, and the procedure Brian describes here does work.
The above problem is due to browser cache. Sitecore DMS Search event stores the single value for one word if we don't close the browser or need to search from the different browser to store the value. If this kind of problem occurs, then search for different keywords by closing the browser and then clearing the cache. This works for me.
Hi i m new to Sitecore. I want to know how to access any table values from Sitecore Web Database through Sitecore API as i want to fill dropdownlist from a table inside sitecore_web database.How can we use Sitecore Queries to access data from Sitecore_Web Database?
I don't suggest you to access directly Sitecore_Web Database.What do you want to do exactly ?
Sitecore Api has a lot of classes, methods for accesing sitecore items but you don't access directly databases .
Maybe this link will help you.
You need to create some items to fill your dropdown list.
An item is a record in a database. Items are the basic building block of a Sitecore site. An item may represent any kind of information, e.g. a piece of content, a media file, a layout etc.
Items always have a name and and ID that uniquely identifies the item within the database. Items have a template that defines which fields the item contains. An item represent a single version of piece of content is a single language.
An item can be retrieved from a database using Items.
An item may have a number of subitems or children. These child items can be accessed through the Children property. The resulting items are checked for security and workflow before being returned. So while an item may have subitems, the current user may be denied access to them. The Parent property define the single parent item of this item.
An item represents a single version in a single language of a piece of content. The language of the item can be obtained from the Language property, while the version is available from the Version property.
The item must be in Editing state before the name or any field values can be changed. If not, an exception is raised. To enter the Editing state use the BeginEdit method and to end it, use the EndEdit method. The EditContext class can be used as a shortcut to BeginEdit/EndEdit.
I get this from Sitecore Api Documentation
As sitecore climber stated, you would not access the Sitecore database directly - this is not something which is supported by Sitecore. Typically you would achieve this through the Sitecore API using the following steps:
retrieve a node from the Sitecore tree which contains child items representing your dropdown items
retrieve the child items
databind your dropdown list to the list of child items
In an ascx, you could have something like this:
<asp:DropDownList ID="exampleDropDown" runat="server"/>
and in the code-behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
var item = Sitecore.Context.Database.GetItem("/sitecore/content/SiteData/StuffForADropDownList");
if (item != null)
{
exampleDropDown.DataTextField = "Text";
exampleDropDown.DataValueField = "Value";
exampleDropDown.DataSource = from i in item.Children.AsEnumerable<Sitecore.Data.Items.Item>()
select new
{
Text = i["Text"],
Value = i.ID.ToString()
};
exampleDropDown.DataBind();
}
}
}
This example assumes that you have an item at /sitecore/content/SiteData/StuffForADropDownList with some child items, which each have a field called Text.
Default in Sitecore you will NEVER work with real database objects other then objects filled using the Sitecore API. Sitecore API will provide you with data from your Sitecore back-end.
If you want to fill a dropdown with a list of items as datasource try something like this:
var items = Sitecore.Context.Item.GetChildren().toList();
yourdropdown.Datasource = items;
yourdropdown.Databind();
Obviously setting your Datatext and Datevalue key correctly, but that's standard .Net.
In Sitecore, never directly get data out of your database and use the Sitecore API.
Please use the built in services to access the sitecore items. It provides the option to select the database in the Get Item method.
You can access the sitecore service with the below URL:
{Your Site}/sitecore/shell/webservice/service.asmx