Free Support Forum - groupdocs.com

How do join multiple search queries for OR operator?

Hi,

I’ve been reading the documentation but can’t seem to figure this out. Say I have multiple Search Queries that use the RegEx Query format, how do I combine all of these queries into one search? If I use SearchQuery.CreatePhraseSearchQuery then I don’t get any results where as if I do SearchQuery.CreateOrQuery then I do get results but I’m only limited to using two queries when using CreateOrQuery.

In short, I need to do a SearchQuery using multiple RegEx patterns but don’t currently see an easy way to do this without creating multiple OR queries which will then become messy. PhraseQuery seems like it’d do the job but I don’t get any results, presumably it’s not using an OR type of search.

Any ideas?

Thanks

@Dezmond

Could you please share the test/sample code and the problematic files? Are you evaluating the API in trial mode (without License)?

@Atir_Tahir

Yep just trailing it without a license to mess around with first.

Phrase Search - No Results despite having file contents that match the RegEx expressions:
SearchQuery subquery1 = SearchQuery.CreateRegexQuery("^4[0-9]{12}(?:[0-9]{3})?$");
SearchQuery subquery2 = SearchQuery.CreateRegexQuery("^(?:5[1-5]|222[1-9]|22[3-9][0- 9]|2[3-6][0-9][0-9]|27[0-1][0-9]|2720)\d+$");
SearchQuery subquery3 = SearchQuery.CreateRegexQuery("^(34|37)\d+$");
SearchQuery query = SearchQuery.CreatePhraseSearchQuery(subquery1, subquery2, subquery3);

OR Search which finds the results in contents of files of subquery1 and subquery2 but can’t add subquery3
SearchQuery subquery1 = SearchQuery.CreateRegexQuery("^4[0-9]{12}(?:[0-9]{3})?$");
SearchQuery subquery2 = SearchQuery.CreateRegexQuery("^(?:5[1-5]|222[1-9]|22[3-9][0-9]|2[3-6][0-9][0-9]|27[0-1][0-9]|2720)\d+$");
SearchQuery subquery3 = SearchQuery.CreateRegexQuery("^(34|37)\d+$");
SearchQuery query = SearchQuery.CreateOrQuery(subquery1, subquery2);

Create a text file with the number 5555555555554444 for example. Note you get results when using CreateOrQuery but you do not if you use CreatePhraseSearchQuery.

I am guessing that CreatePhraseSearchQuery shouldn’t be used for this purpose, really we need a CreateOrQuery function that accepts multiple subqueries instead of just two or give the option that the PhraseSearch performs an OR operation through multiple files in the index.

Thanks

@Dezmond

We are investigating this scenario. Your investigation ticket ID SEARCHNET-2555. We’ll notify you in case of any update.

@Dezmond

Please have a look at the following code:

SearchQuery subquery1 = SearchQuery.CreateRegexQuery("^4[0-9]{12}(?:[0-9]{3})?$");
SearchQuery subquery2 = SearchQuery.CreateRegexQuery("^(?:5[1-5]|222[1-9]|22[3-9][0-9]|2[3-6][0-9][0-9]|27[0-1][0-9]|2720)\d+$");
SearchQuery subquery3 = SearchQuery.CreateRegexQuery("^(34|37)\d+$");
SearchQuery subquery12 = SearchQuery.CreateOrQuery(subquery1, subquery2);
SearchQuery query = SearchQuery.CreateOrQuery(subquery12, subquery3); 

Phrase search query searches for a specific phrase, that is, a specific sequence of consecutive words in each individual document. The OR query returns those documents where there is either the left or right subquery, or both.
In this case, the OR query can be extended by adding an already created query to the super-query, with an unlimited degree of nesting.

Thanks @Atir_Tahir ! So right now we need to keep making nested queries - is there any plans on allowing multiple queries to be specified in CreateOrQuery instead of constantly nesting queries?

Thanks again

1 Like

@Dezmond

We’ll look into the possibility and let you know about the outcomes.

1 Like

@Dezmond

We’ve created a new ticket (SEARCHNET-2556) where we’ll investigate the possibility to allow multiple queries to be specified in CreateOrQuery. But we cannot share any ETA at the moment. You’ll be notified as there’s any further update.