Try our conversational search powered by Generative AI!

How to implement "like" functionality in search technique



My question might be simple but your sugestions can save a lot of time for me.

I'm trying to get the results from all the indexes if a string or part of the string is exist in the document.

I tried MoreLike method which is described in documentation, but unfortunately that is not working.


ITypeSearch<ImageVaultNonDoc> query = client.Search<ImageVaultNonDoc>()
                .Filter(x => x.AlbumId.In(lstImageVaultAlbums));
var results = query.MoreLike(Query).OrderByDescending(orderby => orderby.CreatedDate)
                    .Select(x2 => new ImageVaultFiles
                        Id = x2.Id,
                        Name = x2.Name,
                        PortalTitle = x2.PortalTitle,
                        AlbumId = x2.AlbumId
                    .IncludeType<ImageVaultFiles, ImageVaultDoc>(x1 => new ImageVaultFiles
                        Id = x1.Id,
                        Name = x1.Name,
                        PortalTitle = x1.PortalTitle,
                        AlbumId = x1.AlbumId


Can you please check my code and leave your suggestions here.

Many Thanks.


Kishore T.

Feb 28, 2014 9:53

Why not simply use .For()? Or do you need to get hits on parts of words? If that is the case, then perhaps a wildcard search is what you need. Or, perhaps .PreFix or .AnyWordBeginsWith ?

Feb 28, 2014 10:36

Hi Skuseth,

Thanks for your reply.

.For() is working fine enough if the complete wordis matched, but not if the part of the word is matched.

Below is my requirement:

Keywords: Hello World
1) Result: Bring back anything contains "HELLO" or "WORLD". If the result contains not the exact word such as "HELLOMYFRIEND" or      "WELCOMETOMYWORLD", they are considered hit too and should be brought back.

2) The above searching should happen over the entire indexes but not limited to any specefic field (similar to how we user For() )

So, because of point no(2), I can't use Wild Card search also.


Any other ideas please.


Feb 28, 2014 10:53

Any particular reason why you would want to search across all fields? If you do that, then you may get a match on hits you do not wish for. For example, in your case, if you wild card search across all fields, with query set to "Image", you would get a match on every hit, as it would get a hit on the "type" field, which is "ImageVaultNonDoc" in this case.  I would recommend that you do specify the fields. Doing a wild card search across all the fields does not sound like a good idea performance wise.

I would suggest that you use wild card search and specify the fields.
Optionally, you could create an extension method that will return all string based properties, and then index that. You could then do a wild card search against that single field. The last method migth be better performance wise as well.

I hope this helps! :-)

Feb 28, 2014 11:30

Here is a extension we use to do a word*-search on all field.

public static class SearchExtensions

        public static IQueriedSearch<ISearchContent> UnifiedSearchGraspingRightHandTruncationFor(this IClient client, string query, Language language)
            language = language ?? Language.None;
            return client.Search<ISearchContent>(language).GraspingRightHandTruncationFor<ISearchContent>(query).WithAndAsDefaultOperator().InAllField();

        public static IQueriedSearch<TSource, QueryStringQuery> GraspingRightHandTruncationFor<TSource>(this ITypeSearch<TSource> search, string queryString)
            if (search == null)
                throw new ArgumentNullException("search");
            var str = (string.IsNullOrWhiteSpace(queryString) ? "" : queryString);

            str += !str.Contains("\"") ? "*" : "";

            return new Search<TSource, QueryStringQuery>(search, (ISearchContext context) =>
                var queryStringQuery = new QueryStringQuery(str);
                context.RequestBody.Query = queryStringQuery;


Feb 28, 2014 12:28

Henrik's code should work, you just need to add a * to the start of the query, so that you'll get a *word*-search working. 

I would still suggest specifying fields though :-D 

Feb 28, 2014 13:09
Dear Henrik and Skuseth, Your suggestion is worked perfectly for me. Many thanks, Kishore T.
Mar 03, 2014 8:00
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.