Change NamespaceManager on Full Text Search GAE - google-app-engine

We have an application in GAE, and we are reenginering this to use Full Text. We have to index all data already in the GAE and our application also use namespaces.
We are trying to create a java procedure to be runned by administrator, who has not namespace. In other services, we have created similar java procedures, applying namespace by code, so the idea is to index all data in each namespace. (We use NamespaceFilter to control user domain.)
This is part of code:
private static final Index INDEX = SearchServiceFactory.getSearchService()
.getIndex(IndexSpec.newBuilder().setName("Actividad"));
NamespaceManager.set("userdomain1");
INDEX.add(doc);
Setting namespace is ignored.
Is this the expected behaviour? Is there an alternative way to index all the information in every namespace?
With similar code on datastore it's work fine.

A SearchService object is bound to a namespace, so you need to call NamespaceManager.set() before calling SearchServiceFactory.getSearchService(). Alternatively, call the version of getSearchService() that has a namespace parameter. See:
https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/search/SearchServiceFactory#getSearchService(java.lang.String)

Related

How do you specify the SQLite database file in FireDAC's TFDPhysSQLiteDriverLink component?

I'm trying to modify one of the FireDAC sample projects in order to use an existing SQLite file as the database source. The sample works fine unmodified and connects to its database. However, I can't figure out where the database it connects to is specified, in order to change it.
According to the documentation, there should be a Database property on the TFDPhysSQLiteDriverLink component. There isn't: it doesn't exist. I even converted the form to text and looked through all components' customized properties, and there's no path defined anywhere. Nor is there in code - the sample is very small and there's no path defined at all.
The other option on the documentation is to include the FireDAC.Phys.SQLite unit, although that doesn't explain how to set the database, since as far as I can tell that unit just includes the component. And when I search for Database properties (see attached image) none of them in any class in that unit seem to be quite what I'm after. The closest is a string that's for a backup component - I doubt that's what I need. There is a SQLiteDatabase property in the TFDPhysSQLiteConnection class but that's read-only.
List of all Database properties defined in the FireDAC.Phys.SQLite unit
I also tried creating a temporary connection definition at runtime, by double-clicking the TFDConnection component. That only gives an exception:
Exception double-clicking the TFDConnection component
The only solution to this I found is in the XE5 documentation, where it says to set the $(PUBLICDOCUMENTSDIR) environment variable. I already had to do that to get the demo to run (previously, it threw the same exception on the line FDConnection1.Connected := True;; it doesn't now, the demo runs perfectly at runtime.) That change obviously hasn't affected the designer, and I don't even know if I'm looking in the right place, since after all the documentation talks about setting the Database property.
So I'm stumped. Where does it set the database? It's not in the DFM or any streamed properties; it's not in the property defined by the documentation (TFDPhysSQLiteDriverLink.Database doesn't exist, nor does anything that looks like it); it's not in the TFDConnection designtime editor (even though it throws an exception, a file specified as a property here would appear in the streamed DFM, I'd think); it's not in code; ...where else can it be?
(I have never used FireDAC before so am a complete noob, btw. I'm self-teaching via the documentation and samples.)
You don't actually need a TFDPhysSQLiteDriverLink for a minimalist FireDAC project, and using one rather confuses the issue if you're trying to make a connection to a database for the first time.
Try this:
Make a note of the name including path of a Sqlite db.
Start a new VCL project and drop a TFDconnection, TFDQuery, TDataSource & TDBGrid onto its form and connection them up. Set the TDFQuery's Sql to select * from some table you know exists in the db.
Right-click the TFDConnection and select Connection editor from the pop-up.
Set the DriverID to SQLite and insert your db name into the Database Value box.
Open the FDQuery.
If you compile and run the project, you'll get an exception telling you a class factory for a TFDGUIxWaitCursor is missing (this is the sort of thing I love about FireDAC), but that's easily fixed by dropping one onto your form. Notice that you don't have to connect it using the Object Inspector to any of the other FD components.
After that, you can add a TFDPhysSQLiteDriverLink and set its DriverID to the same as for the TFDConnection.
I ussualy roll my own class and handle the OnBeforeConnect event
Something like this
procedure TSQLiteConnection.SQLiteConnectionBeforeConnect(Sender: TObject);
begin
if not(TFile.Exists(DatabaseFilePath)) then
Params.Values['OpenMode'] := 'CreateUTF16'
else
Params.Values['OpenMode'] := 'ReadWrite';
Params.Values['Database'] := DatabaseFilePath;
DriverName := 'SQLite';
end;
The DatabaseFilePath is just a string field of the class, so basically you can put any file path there
TSQLiteConnection is, of course, a TFDConnection descendant

Close method not working in Office

Im trying to use Microsoft.Office.Interop.Word._Document.Close() in a .net 3.5 windows form app.
No matter how much I search here and on Google I cannot find the correct parameters to put in the Close method.
I am using version 14.0.0.0 of Microsoft.Office.Interop.Word and I would like to close the document without saving and ideally ensure that the application can isolate the document thread so that users can still open word documents outside the running application.
See the Close method of the Document class described in MSDN. If you need to omit the parameter and use the default value - pass the Type.Missing parameter.
Try this:
object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
object missing = System.Reflection.Missing.Value;
_Document.Close(ref doNotSaveChanges, ref missing, ref missing);
This is the source
I'm not sure if you'll need the middle line or not. It's not from the original source it's from here

How to list all datasets in CKAN (not only the active ones)

I am working on a project based on CKAN, and I am required to list in a page all the datasets that have the state "active" and "draft". When you go to the datasets page, you can only see the ones that have the state marked as "active", but not "draft".
If I use the API (call the package_list() method) or REST calls (http://localhost/api/3/action/package_list), CKAN only returns "active" datasets, but not "drafts". I double and triple checked the documentation, and apparently one cannot lists the datasets by their state.
Does anybody have a clue on how to do this? Has anybody done this already?
Thanks!
If nothing else, you could write an extension to do this. The database call itself will be pretty simple:
SELECT id,title,name FROM package WHERE state='active' OR state='draft';
I managed to modify CKAN core to list the datasets that do not have the state "draft" or "deleted", and it works, but I do no want to touch CKAN's core, I want to do this using a plugin, so the normal thing to do is to implement plugins.IActions and override the package_list method with a custom one. I have already written my own extension to try to modify CKAN behavior on method package_list(), but I can't seem to figure it out how to make it work.
Here is my code:
#side_effect_free
def package_list_custom(context, data_dict=None):
datasets = []
dataset_q = (model.Session.query(model.Package)
.join(model.PackageRole))
for dataset in dataset_q:
if dataset.state != 'draft' and dataset.state != 'deleted':
datasets.append(dataset)
return [dataset.id for dataset in datasets]
class Cnaf_WorkflowPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IActions)
def get_actions(self):
return {
'package_list' : package_list_custom
}
If I modify CKAN core it works very well, but the problem is that I am not to touch it, so I am obliged to do it via an extension.
EDIT: Ok, I managed to make it work, you need to decorate the method with #side_effect_free. I modified my code, and now it works.
The package_search API is capable of this, by searching for state:draft and setting the include_drafts=True flag. Something like this:
https://my-site.com/api/action/package_search?q=state:draft&include_drafts=True
You should be able to access this from a plugin with something like: ckan.plugins.toolkit.get_action('package_search')(context=context, data_dict={'q': 'state:draft', 'include_drafts': True}) (you'll need to assemble the context yourself, containing a 'user' key for the current username and a 'userobj' key for the current user object).
Then make a page from the results.

Persistent data for winform c#

I have a web poster application and I want to create a "Definition" file for it. Basically just a bunch of strings I import into the program at startup. I want them in an external source so I can update it without changing the executable.
I was thinking of creating a new static class, say "PosterDefinition", and on the startup of the application import the definition file, and set the PosterDefintion values from there.
As for how I will save it, maybe serialize the data from the program itself (a one time process).
Please share your thoughts.
Thanks.
I would suggest that you save it in an XML file. This would allow you to get the data quickly using LINQ-XML. What you could do is make properties that look at the file for making changes. You could cache values in the Application object. After a few requests, or after each one, check on the file. Because LINQ, or better yet PLINQ, excecutes quickly, the requests would not take long.
Here is an example XML document:
<?xml version="1.0" encoding="utf-8"?>
<Definition>
<Item>
<Title>t</Title>
<Something>Pie</Something>
</Item>
</Definition>
And here is how to access the Something of an item with Title t
using System.Xml;
using System.Xml.Linq;
XElement element = XElement.Load("definitions.xml");
XElement item = (from item in element.Elements()
where item.Elements().Where(i => (string)i.Element("Title") == "t")
select item.Element("Something")).First();
I havn't tested this and I am bad at LINQ so check this.

Why do XML Namespaces usually start with http://...?

For example, the WPF namespace is:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
If I define my own namespace, should it also start with http? Isn't http misleading?
Namespaces doesn't have any meaning in their value, except for that value to be unique to avoid nameclashing. This is why you see a lot of companies putting in the URL for their own website as the namespace. URLs serve the same purpose, to be unique. Over the years it's just become good practice to use an URL, because if everyone does that, no nameclashing should occur :)
The W3C Document defining XML Namespaces says (quoting) :
Definition: An XML namespace is
identified by a URI reference
[RFC3986]
And RFC 3986 says (quoting) :
1.1.1. Generic Syntax
Each URI begins with a scheme name,
as defined in Section 3.1, that
refers to a specification for
assigning identifiers within that
scheme.
So I guess using http:// is what's closest to the standard -- as HTTP is the most common scheme used on the net.
In addition, as there can be only one owner for a domain name, it allows each company to use it's URL in its namespaces.
Another common way instead of using a URL starting with http:// is to use a Uniform Resource Name whose format is defined by RFC2141.
Such namespace identifiers are e.g. used by ODF (OpenDocument Format):
urn:oasis:names:tc:opendocument:xmlns:office:1.0
urn:oasis:names:tc:opendocument:xmlns:style:1.0
urn:oasis:names:tc:opendocument:xmlns:text:1.0
From this article at W3Schools:
"The namespace URI is not used by the parser to look up information. The purpose is to give the namespace a unique name. However, often companies use the namespace as a pointer to a web page containing namespace information. Try to go to http://www.w3.org/TR/html4/."
It is a reliable way to create a readable globally unique identifier. It may or may not be to a valid URL with more information.

Resources