tags:

views:

310

answers:

2

This is quite a monster query I am writing.

A very quick description of the database: You have an image table, an imagetag table, which joins it to a tag table. Images can have 0 or many tags.

I have a query which does a full text search on the Image's title property and this works fine.

However, I want it so when you do a full text search, it also looks at the image's tag names to see if anything matches. For instance, you could have an image with a title of "Awesome Cakes", which has a tag of cooking. When a user does a full text search of cooking, it should find that image, because it has a corresponding tag.

Right?

So as I mentioned I have my fulltext method which works and returns a queryable list of images.

I have also made a method which finds images with matching tags to the full text query

IQueryable<Image> results = imageService.FullTextSearch(MakeSearchTerm(freeText));
IQueryable<Image> tagResults = imageService.FullTextTagSearch(freeText, tagService);

When I debug this and view the enumerations, they both have results.

What I want to do is union them into one result set.

The reason I want to do this, is later down the code, other filters are applied to the results before the actual query is executed, such as filtering by author and only taking the results needed for the particular page.

Unfortunately, when I try and union:

results = results.Concat(tagResults).Distinct();

Types in Union or Concat cannot be constructed with hierarchy.

I understand that this might not be possible :p But I'm just seeing if there are any good ideas and solutions, cheers.

A: 

I think there is a problem in the way you approach searching. Instead of returning Images, you should introduce a type that only captures the image metadata, with a key to the image.

I dont't get exactly what "Types in Union or Concat cannot be constructed with hierarchy" should mean though. Is that an exception?

Johannes Rudolph
Yeah that's an exception
qui
A: 

I would try combining the FullTextSearch and FullTextTagSearch functions into something like this:

public IQueryable<Image> ImageSearch(string fullText)
{
    return from image in ImageTable
           where image.title.Contains(fullText) 
               || image.tagName.Contains(fullText)
           select image;
}
theprise