Is it possible to find all Ember components based on their name using a wildcard or regex?
so far I found a way to find a component by its fullName:
appInstance.lookup('component:my-component')
but what I want to achieve is to do something like:
appInstance.lookup('component:my-*')
which will return an array of components whose name begins with 'my-'
You can list the names of all entries by using require.entries:
function getKeys(){
return Object.keys(require.entries).filter(function(key){
return /.*components\/my-.*/.test(key);
};
Then you can make a lookup with this keys. (Be aware that function getKeys returns both component's js file names and template file names.)
Related
I am working on integrating Elastic Search in my existing Django REST application. I am using the django-dsl-drf module provided in the link below:
https://django-elasticsearch-dsl-drf.readthedocs.io/
In their documentation 'exclude' query param is provided. But the query only when we provide the full field value.
search-url?exclude=<field-value
For eg: If I have a value 'Stackoverflow' in field 'name'. I'll have to provide query param a
?name__exclude=Stackoverflow to exclude records having 'Stackoverflow' as name in the result. I would like to implement a search in such a way that when I provide 'over', I need to exclude these records, similar to ?name__exclude=over
I checked the above tutorial, but I couldn't find it. Is there any work around so that I can exclude records, fields containing terms instead of providing full field value, which is also case-insensitive.
Thanks a lot.
Using the contains functional filter, you can target documents that have their name field value containing the characters over anywhere in their terms:
?name__contains=over
However, as far as I know, there is no way to negate that filter in django-dsl-drf. You can create an issue requesting that feature, though, because odds are high that you're not the only who needs that, since it's a pretty common way of searching.
Is there a way to set our own index name in Django models? Currently, the migration scripts would create a name in format [table_name]_9fcb4ba3 and I'd like to have the name more descriptive, i.e. [table_name]_[column_name] or so.
On the Django's Model Field Reference page, it doesn't seem to have such option (https://docs.djangoproject.com/en/1.8/ref/models/fields/#db-index)
For anyone finding its way from Google - seems Django 1.11 allows you now to have a custom name for indexes. Following the documentation as described here:
Index.name
The name of the index. If name isn’t provided Django will auto-generate a name. For compatibility with different databases, index names cannot be longer than 30 characters and shouldn’t start with a number (0-9) or underscore (_).
There is no way of customizing the name for indexes as these are generated by hashing (the index name calculation uses some hashing techniques)
If I call Ember.inspect(component), I get a response like:
<app#component:my-component::ember1246>
This suggests that the component is aware of its own name (my-component). Is there a way to access just that name?
Ember.inspect() calls the objects toString() which in turn calls some internal ember metal functions to derive the name.
There is however an internal property which people have been using to get the name:
this.__proto__._debugContainerKey
This outputs component:my-component, then you can just split on :. There's an issue which will create a public way of exposing object meta information which we'll be able to use in the future: https://github.com/emberjs/ember.js/issues/10742
This regex will do the trick:
//Returns a string with full name of component, like: <ProjectName#component:path/to/component-name::ember793>
let componentName = this.toString ();
//This regex will match the component and capture the latest part of component path.
let regex = componentName.match (/<[a-zA-Z]+#[a-zA-Z]+:(?:[a-z]+[\/])*([-a-z]+)::[a-zA-Z]+[0-9]+>/);
//The latest element of array is the component name.
console.log (regex[regex.length-1]); //component-name
See https://regex101.com/r/rX9bQ7/3 for full explanation about how this works.
Using the Google CTemplate library, I have built a TemplateDictionary of params. Such a dictionary is a map of string keys to a variety of value types.
Typically, one passes CTemplate a template file wherein placeholders for each key in the dictionary are found and substituted.
In one case, though, I wish to emit the entire dictionary in JSON form, and the template language syntax doesn't appear to provide reflection such that I can write placeholders to loop over an unknown number of unknown keys in any arbitrary dictionary.
Did I miss some functionality?
If so, how can I add it?
Will I have to patch the CTemplate code? Much of what I seem to need for the job appears to be marked private i.e. for internal use only...
I've ended up hacking the CTemplate source in template_dictionary.h and template_dictionary.cc, cloning class class TemplateDictionary::DictionaryPrinter to produce a new class class TemplateDictionary::DictionaryJsonPrinter, adapting its member functions to emit JSON syntax.
I've got a Haystack/xapian search index for django.contrib.auth.models.User. The template is simply
{{object.get_full_name}}
as I intend for a user to type in a name and be able to search for it.
My issue is this: if I search, say, Sri (my full first name) I come up with a result for the user object pertaining to my name. However, if I search Sri Ragh - that is, my full name, and part of my last name, I get no results.
How can I set Haystack up so that I can get the appropriate results for partial queries?
(I essentially want it to search *Sri Ragh*, but I don't know if wildcards would actually do the trick, or how to implement them).
This is my search query:
results = SearchQuerySet().filter(content='Sri Ragh')
I use to have a similar problem, as workaround or maybe a Fix you can change the query lookup
results = SearchQuerySet().filter(content__startswith='Sri Ragh')
The issue is that django-haystack doesn't implement all lingos from search engines. Of course you can do this.
results = SearchQuerySet().raw_search('READ THE SEARCH ENGINE QUERY SYNTAX FOR GET WILDCARD LOOKUPS')
As Django-haystack says, this is not portable.
You can use icontains or startswith.
Be careful with this one, if a query is for example 'r', this will bring you all 'Model' entities that have a 'r' in its content.
Model.objects.filter(content__icontains=query)
Model.objects.filter(content__startswith=query)
Look at the documentation