0

I am trying to build the lucene fulltext search with the wildcard expression to represent "Contains" /*.<Keyword>/*, but in the Buildparameter model which is provided by the Azure Search library does not have the search properties.

I am using

Documents.Search<T>(searchTerm, searchParam);

//where SearchTerm is the <typed key search> for ex "Nurs" and the result 
//should be where all or any text contains "Nurs"

The Azure.Search.Models SearchParameter which i am using to build is where i Extended to create the new class to contain the Search field.

        return new ExtentedSearchParameter
         {
            IncludeTotalResultCount = true,
            SearchFields = new List<string>() {"FilterableTitle", "FilterableAlternativeTitle"},
            Skip = (properties.Page - 1) * properties.Count,
            Top = properties.Count,
            Search=properties.SearchQuery,
            QueryType = QueryType.Full ,
            Select=new List<string>(){"FilterableTitle", "FilterableAlternativeTitle"},
            OrderBy = properties.OrderByFields,
        };

and in my application I am building the query like

  if (string.IsNullOrWhiteSpace(returnProperties.FilterBy))
        {
            returnProperties.SearchQuery =$"FilterableTitle: /.*'{cleanSearchTerm.TrimStart('\"').TrimEnd('\"')}.*/' and FilterableAlternativeTitle:/.*'{cleanSearchTerm.TrimStart('\"').TrimEnd('\"')}.*/'";
        }

When I am passing the searchparameter and the search term its not returning the result and its throwing an exception.

Bruce Johnston
  • 8,344
  • 3
  • 32
  • 42
Dinesh
  • 193
  • 2
  • 14
  • Why are you extending the SearchParameters class? This shouldn't be necessary. – Bruce Johnston Nov 07 '17 at 23:42
  • I want to do the full text search with any / contains keyword . I want to create a search query with – Dinesh Nov 08 '17 at 10:03
  • Instead of extending the SearchParameters class, try passing your Lucene query as the searchText parameter to the Search method. If that doesn’t work, please edit your question to provide more details such as the specific error message you receive. If it does work, let me know and I’ll write up this comment as an answer. – Bruce Johnston Nov 08 '17 at 14:41
  • Hi Bruce , Thanks . it worked. I removed the filter and passed the lucene search query in the search method. Cheers mate :) – Dinesh Nov 09 '17 at 15:14
  • Happy to help. :) Please accept the answer below. – Bruce Johnston Nov 09 '17 at 20:13

1 Answers1

1

Instead of extending the SearchParameters class, you can pass your Lucene query as the searchText parameter to the Search method:

Documents.Search<T>(properties.SearchQuery, searchParam);
Bruce Johnston
  • 8,344
  • 3
  • 32
  • 42