WhereExpression method not found in SubSonic 3.0.0.4? - subsonic3

This is my first ever post on any forum, so excuse my etiquette.
Im using SubSonic 3.0.0.4 and was trying to concat a Fluent Query using ActiveRecord, I want to be able to use the WhereExpression method of SqlQuery to start adding a list of 'OR' statements with brackets round, to exclude the list from other constraints E.g.
var qry =
db.Select.From<DocumentHeader>();
qry.WhereExpression(DocumentHeadersTable.InvoiceNoColumn).Like(myList.Items[0]);
for (Int32 i = 1, n = myList.Items.Count; i < n; i++) {
qry.Or(DocumentHeadersTable.InvoiceNoColumn).Like(myList.Items[i]);
}
qry.CloseExpression();
There is more to it than this but this is a rough example. Searching on the web and looking at the Fluent Query page of SubSonic it suggests that the method WhereExpression does exist, but looking at the Intellisense and then in the source code downloaded from the GitHub, I could only find a Property not a Method. I have managed to do a workaround for the above problem, but the WhereExpression would be useful.
So after all that my question is, has this method been removed? or its usage changed? Or most likely Im being stupid and looking in the wrong place?
Thanks in advance.
Lee

Apparently, the WhereExpression got another implementation due to a massive addition of LINQ support in the version 3.0, so just use the Where method instead.

Related

Django/DRF filtering

I filter my list of Product models by title field. For example, I want to find this title = 'Happy cake'. And if I type
Case 1. 'happy cake',
Case 2. 'hapy cake', happi kake'
it should return me 'Happy cake'.As I know icontains helps me with case 1. How can I get that?May be some sort of technologies should be added or django itself has appropriate solution?
You can try using the lookup __in
Model.objects.filter(title__in=['happy cake', 'happi kake'])
You can put as many test cases you want in the list.
You can do this other way.
If you are sure about the start ha here
Happy Cake
Hapy cake
happi kake
Product.objects.filter(title__startswith='ha')
This kind of question is hard to solve by just using Django inbuild search system. So this is one way to solve this question. ElasticSearch. It has fuzzy search and indexing. Cool thing to deal with tough tasks). I pushed to git some starting code. It doesn't solve this question fully, but with some workaround that goal can be achieved.

How to specify delimiter for list.each function in ColdFusion 11?

I have adopted the CFScript syntax for most of the work with ColdFusion now, since with the new version of ColdFusion v11(codenamed Splender), almost all the short-comings of the script style syntax has been given serious thoughts. Thought suprisingly, I came across a requirement where I needed to iterate throught the list with variable delimiter. So I choose the list.each function in CF11 and not any other option would do since I also need the current index value along the way as well.
list.each(function(element,index,list){
writeOutput("#index#:#element#;");
}, ";")
The problem is that this function surprisingly does not seem to support a custom delimiter.
To save the time, I would like to mention that I already tried the for (element in...) with a count variable for my needs.
var idx=1;
for (element in "a,b,c,d,e"){
writeOutput(element);
LOCAL.idx++;
}
But I would appreciate some help with the original list.each function in CF11, is it even possible somehow to implement? or is it what I think a shortcoming.
I'm not using CF11, but i would point you to this bug report, which seems to say the HF3 does exactly what you want.
If that doesn't work, or in the meantime, you could convert it to an array and use ArrayEach().

Mongoid 4 finding embedded documents by ID

I have a project that is my first serious dive into Mongoid.
I saw a tip to use the following command:
Parent.where('childrens._id' => Moped::BSON::ObjectId(params[:id])).first
But this doesn't work. Error message was:
NameError: uninitialized constant Moped::BSON
I found that BSON is no longer included, so I added it to my Gemfile, as well as Moped. Then, I did another fix I found (placing Moped::BSON=BSON in application.rb).
This still didn't work, but the error changed to:
NoMethodError: undefined method `ObjectId' for BSON:Module
So I am assuming that this method got deprecated or something. Does anyone have any other tips?
Just to be clear, I am finding myself in the situation where I want to sort embedded documents using jquery-sortable. This requires me to update them in the database, but the serialize from that doesn't include the parent document in the hash. So I figured I'd try to get it on the back end using an ID from the embedded document. That is why I need it.
Thanks again for any help you can provide.
Try simply:
Parent.where('childrens._id' => params[:id]).first
I have solved the question though this won't be of much help to people in the future. The requirements have changed and now I am using human-readable strings as IDs to assist in friendly URLs and some other stuff.
Therefore, I don't have any issues with ObjectIds. Cortex's solution should (from what I have read) work for dealing with ObjectIds but I cannot verify it now.

Query with RegExp and Array

I have a class Post, with the following scope:
scope :by_tag, ->(tag){ where(:desc => /##{Regexp.escape(tag)}/) }
It works very well with one tags, but I can't make it work with various tags.
For example: I cant make it give me the posts tagged with #rails AND #regexp.
With criteria union I can make it return me the posts tagged with #rails OR #regexp.
How can I get it to work? I'm using mongoid, btw.
Thanks in advance.
Just fount that is not an OR. What happens is that the second time I call by_tag, it overrides the previous. I believe that's because it's the same property.
Someone know how to fix this? Thanks
Regexp queries tend to be really slow. Instead, store an array of tags and use $in to query the array.
With Mongoid 2.x use all_in
scope :by_tags, ->(*tags) { all_in(tags: *tags) }
With Mongoid 3 use all merge strategy
scope :by_tags, ->(*tags) { all(tags: *tags) }

How do you access/configure summaries/snippets in Django Haystack

I'm working on getting django-haystack set up on my site, and am trying to have snippets in my search results roughly like so:
Title of result one about Wikis ...this special thing about wiki values is that...I always use a wiki when I walk...snippet value three talks about wikis too...and here's another snippet value
about wikis.
I know there's a template tag that uses Haystack code to do the the highlighting, but the snippets it generates are pretty limited:
they always start with the query word
there's only one snippet value
they don't support asterisk queries
and other stuff?
Is there a way to use the Solr backend to generate proper snippets as shown above?
Bottom line is that the Solr highlighting can't really be used by Haystack in a flexible way. I spoke to the main developer for Haystack on IRC, and he said basically, if I want to have the kind of highlighting I'm looking for, the only way to get it is to extend the Solr backend that Haystack uses.
I dabbled in that for about half a day, but couldn't get Haystack to recognize my custom back end. Haystack has some magic backend loading code that just wasn't working with me.
Consequently, I've switched over to sunburnt, which provides a lighter-weight and more extensible wrapper around Solr. I'm hoping it will fare better.
from haystack.utils import Highlighter
my_text = 'This is a sample block that would be more meaningful in real life.'
my_query = 'block meaningful'
highlight = Highlighter(my_query)
highlight.highlight(my_text)
http://docs.haystacksearch.org/dev/highlighting.html