New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to do an AND search for multiple params? #1

Closed
JamesReate opened this Issue Nov 19, 2014 · 13 comments

Comments

Projects
None yet
2 participants
@JamesReate

Hi, your libary is awesome, really helped me out!

So, given the following example:
query = query.Search(x => x.Code, x => x.Name, x => x.Brand) .Containing(stringArray);
How would I do to get the results filtered by the multiple strings in the stringArray ? Currently I see the result is additive. Or is this a feature you're still working on? I cloned your code but I don't have much experience with LINQ expressions, so i've been kind of lost trying to tweak it.

To clarify what i mean, lets say that for the two properties Name and Brand I have the following table:

| Name | Brand


1 | doggy | Nutram
2 | ring | Nutram

If the containg has params ("nutram", "ring") I should only get back result #2....

Thanks, appreciate any feedback

@ninjanye

This comment has been minimized.

Show comment
Hide comment
@ninjanye

ninjanye Nov 24, 2014

Owner

Hi @JamesReate

I see what you mean. I guess what you are after is a .ContainingAll() method that only returns results that contain all the supplied terms. Is my understanding correct?

Sounds like a great feature to add...

I'm just finishing off a new Levenshtein search feature so once that is complete I'll start working on this.

Thanks for getting in touch. I'll update soon

Owner

ninjanye commented Nov 24, 2014

Hi @JamesReate

I see what you mean. I guess what you are after is a .ContainingAll() method that only returns results that contain all the supplied terms. Is my understanding correct?

Sounds like a great feature to add...

I'm just finishing off a new Levenshtein search feature so once that is complete I'll start working on this.

Thanks for getting in touch. I'll update soon

@ninjanye ninjanye self-assigned this Nov 24, 2014

@ninjanye

This comment has been minimized.

Show comment
Hide comment
@ninjanye

ninjanye Nov 24, 2014

Owner

Hi @JamesReate

Not sure if you could possibly get round the issue by using the following...

query.Search(x => x.Name).Containing(stringArray)
     .Search(x => x.Brand).Containing(stringArray)

This will return results where Name contains any item in stringArray AND Brand contains any item in stringArray

UPDATE
Note, this is different to the ContainingAll() method I mentioned above.

Owner

ninjanye commented Nov 24, 2014

Hi @JamesReate

Not sure if you could possibly get round the issue by using the following...

query.Search(x => x.Name).Containing(stringArray)
     .Search(x => x.Brand).Containing(stringArray)

This will return results where Name contains any item in stringArray AND Brand contains any item in stringArray

UPDATE
Note, this is different to the ContainingAll() method I mentioned above.

@JamesReate

This comment has been minimized.

Show comment
Hide comment
@JamesReate

JamesReate Nov 24, 2014

Great thanks for your reply! I'll give your workaround a try and see what the result is, see what my customers think.

Yes, the ContainingAll method concept you explain is exactly what I meant. Awesome if you end up adding it as a feature :) I looked at your source code, but not exaclty sure how stuff worked, what would I need to learn to be able to help?

Great thanks for your reply! I'll give your workaround a try and see what the result is, see what my customers think.

Yes, the ContainingAll method concept you explain is exactly what I meant. Awesome if you end up adding it as a feature :) I looked at your source code, but not exaclty sure how stuff worked, what would I need to learn to be able to help?

@JamesReate

This comment has been minimized.

Show comment
Hide comment
@JamesReate

JamesReate Nov 24, 2014

I tried the workaround, although didn't do as we needed since it would return 0 results with only one search param, ie. given above table if I search only "nutram" I dont get any results would have to search "nutram" & "doggy".
In our search input we just do a .Split(' ') to get the array of params.

I tried the workaround, although didn't do as we needed since it would return 0 results with only one search param, ie. given above table if I search only "nutram" I dont get any results would have to search "nutram" & "doggy".
In our search input we just do a .Split(' ') to get the array of params.

@ninjanye

This comment has been minimized.

Show comment
Hide comment
@ninjanye

ninjanye Nov 24, 2014

Owner

Yeah the difference between the workaraound and new new ContainingAll() method will be as follows:

Given the following terms to search for:

var options = new[] {"contains", "all", "words"}

And the following data

Id Name Brand
1 contains all words
2 contains words
3 something strange

The workaround

query.Search(x => x.Name).Containing(options)
     .Search(x => x.Brand).Containing(options)

The workaround code will return both record #1 and #2 because the search requests that Name contains any of the options AND Brand contains any of the options

The new feature

The new feature would be something like the following

query.Search(x => x.Name).ContainingAll(options);

This would only return record one as it is the only record that mentions all the options.

Hope that helps to clear things up

Owner

ninjanye commented Nov 24, 2014

Yeah the difference between the workaraound and new new ContainingAll() method will be as follows:

Given the following terms to search for:

var options = new[] {"contains", "all", "words"}

And the following data

Id Name Brand
1 contains all words
2 contains words
3 something strange

The workaround

query.Search(x => x.Name).Containing(options)
     .Search(x => x.Brand).Containing(options)

The workaround code will return both record #1 and #2 because the search requests that Name contains any of the options AND Brand contains any of the options

The new feature

The new feature would be something like the following

query.Search(x => x.Name).ContainingAll(options);

This would only return record one as it is the only record that mentions all the options.

Hope that helps to clear things up

@ninjanye

This comment has been minimized.

Show comment
Hide comment
@ninjanye

ninjanye Nov 24, 2014

Owner

Hi @JamesReate

Just seen you added a comment at the same time I was composing... Yeah, it seems you are going to need the .ContainingAll(). I think things are going to start to get tricksy pretty quickly with different variants of this, for instance:

query.Search(x => x.Name, x => x.Brand).ContainingAll("test", "search");

Should the result of the above return only records where a property (Name, Brand) contains all the search terms or should the code return records where all search terms were matched across all/any of the properties?

The second would have more results in certain cases since it will allow for all the terms to be matched across properties

Thoughts?

Owner

ninjanye commented Nov 24, 2014

Hi @JamesReate

Just seen you added a comment at the same time I was composing... Yeah, it seems you are going to need the .ContainingAll(). I think things are going to start to get tricksy pretty quickly with different variants of this, for instance:

query.Search(x => x.Name, x => x.Brand).ContainingAll("test", "search");

Should the result of the above return only records where a property (Name, Brand) contains all the search terms or should the code return records where all search terms were matched across all/any of the properties?

The second would have more results in certain cases since it will allow for all the terms to be matched across properties

Thoughts?

@JamesReate

This comment has been minimized.

Show comment
Hide comment
@JamesReate

JamesReate Nov 24, 2014

I would go for the 2nd option, which I think is more useful - at least it is what I would use all over my application.

I would go for the 2nd option, which I think is more useful - at least it is what I would use all over my application.

@ninjanye

This comment has been minimized.

Show comment
Hide comment
@ninjanye

ninjanye Nov 24, 2014

Owner

Yeah, agreed. That was preferred option to. Ok let me crack on with it and
I'll keep you posted here.
On 24 Nov 2014 18:29, "James Reategui" notifications@github.com wrote:

I would go for the 2nd option, which I think is more useful - at least it
is what I would use all over my application.


Reply to this email directly or view it on GitHub
#1 (comment)
.

Owner

ninjanye commented Nov 24, 2014

Yeah, agreed. That was preferred option to. Ok let me crack on with it and
I'll keep you posted here.
On 24 Nov 2014 18:29, "James Reategui" notifications@github.com wrote:

I would go for the 2nd option, which I think is more useful - at least it
is what I would use all over my application.


Reply to this email directly or view it on GitHub
#1 (comment)
.

@ninjanye

This comment has been minimized.

Show comment
Hide comment
@ninjanye

ninjanye Nov 25, 2014

Owner

Hi @JamesReate

I have managed to complete this feature so will be pushing out as a package release later today.

I'm not sure what version of SearchExtensions you are using but version 1.3 will include this change. Alternatively, if you prefer, as part of developing the feature, I realised you are able to achieve this goal with the current code (albeit not as elegantly)

var searchTerms = new string[]{"test", "search", "code"};
var query = context.Search(x => Name, x => x.Brand);

foreach(string term in searchTerms){
    query = query.Containing(term);
}

var result = query.ToList();

Obviously this is not as nice as the new feature which will work as follows:

var searchTerms = new string[]{"test", "search", "code"};
var query = context.Search(x => Name, x => x.Brand).ContainingAll(searchTerms);

Will update when I get the package released to the new version.

Thanks again for putting this request in, I would not have realised the need for this feature had you not got in touch.

Cheers

Owner

ninjanye commented Nov 25, 2014

Hi @JamesReate

I have managed to complete this feature so will be pushing out as a package release later today.

I'm not sure what version of SearchExtensions you are using but version 1.3 will include this change. Alternatively, if you prefer, as part of developing the feature, I realised you are able to achieve this goal with the current code (albeit not as elegantly)

var searchTerms = new string[]{"test", "search", "code"};
var query = context.Search(x => Name, x => x.Brand);

foreach(string term in searchTerms){
    query = query.Containing(term);
}

var result = query.ToList();

Obviously this is not as nice as the new feature which will work as follows:

var searchTerms = new string[]{"test", "search", "code"};
var query = context.Search(x => Name, x => x.Brand).ContainingAll(searchTerms);

Will update when I get the package released to the new version.

Thanks again for putting this request in, I would not have realised the need for this feature had you not got in touch.

Cheers

@JamesReate

This comment has been minimized.

Show comment
Hide comment
@JamesReate

JamesReate Nov 25, 2014

That was quick! Thanks a lot, will update the nuget package later today and give it a try. This will really make the search feature in our web app a lot better.

That was quick! Thanks a lot, will update the nuget package later today and give it a try. This will really make the search feature in our web app a lot better.

@ninjanye

This comment has been minimized.

Show comment
Hide comment
@ninjanye

ninjanye Nov 25, 2014

Owner

Hi @JamesReate

Release 1.3 is now up on nuget, so feel free to update and check it out

Cheers

Owner

ninjanye commented Nov 25, 2014

Hi @JamesReate

Release 1.3 is now up on nuget, so feel free to update and check it out

Cheers

@ninjanye ninjanye closed this Nov 25, 2014

@JamesReate

This comment has been minimized.

Show comment
Hide comment
@JamesReate

JamesReate Nov 26, 2014

Yup, it does the trick exactly as expected!

Yup, it does the trick exactly as expected!

@ninjanye

This comment has been minimized.

Show comment
Hide comment
@ninjanye

ninjanye Nov 26, 2014

Owner

Awesome, sorry, closed the issue a little early, should have waited for your confirmation

Owner

ninjanye commented Nov 26, 2014

Awesome, sorry, closed the issue a little early, should have waited for your confirmation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment