Try our conversational search powered by Generative AI!

Searching for all page types by using the inherited type

Nat
Nat
Vote:
 

hi

I am trying to implement find on our site.

we have a load of different page types (too many), but they all inherit from a single type - BasePage. 

if I search with find like so:

var results = Client.Search<BasePage>()
    .For(searchTerm)
    .FilterOnCurrentSite()
    .FilterForVisitor()
    .GetResults()

as I understand it - this will search on the SearchText 'property' of the pages.

however, as I am specifying BasePage, will it then ignore any properties on the inheriting pages which are not also in the BasePage type?

so for isntance

public class SomeOtherPage : BasePage{
   public virtual string SomeOtherProperty {get;set;}
}

will the value of SomeOtherProperty be included in the SearchText() value?

and whilst I am here, is it possible to return results for spelling mistakes automatically, or do I need to realise no results have been returned and work out what I think the user may have been searching for and search again for that?

thanks

#269758
Edited, Jan 10, 2022 15:52
Vote:
 

Hello Nat,

The following is around the spelling mistakes part of the question.

For common spelling mistakes, it might be worth looking at using Synonyms.  This allows you to say a collection of words have the same or similar meanings.  One way synonyms may be terms like "oranges" and "fruit" while bi-directional terms may be more like "bike" and "Bicycle".  If a spelling mistake is very common, you could add a synonym for it, e.g. "skool" and "School".  You can include synonyms by chaining the UsingSynonyms() method on IQueriedSearch.  Have a read over here: Synonyms.

Alternatively you can look into using the DidYouMean functionality.  This doesn't provide search results, but does provide alternate search suggestions that other users have made.  You'll need to be tracking search in order to leverage the power of search statistics.  Read more about that in these articles:

GetResults() also won't work for IContent based objects.  You'll need to use GetContentResult or define a mapping onto a dto for GetResults().  If you do use GetContentResult, you should be able to check and cast onto the main content types if you want to access those higher level properties.

#270002
Jan 14, 2022 16:18
Nat
Vote:
 

Hi Mark

thanks for the reply. 

Yes realised I had just chopped out some code for that little search snippet, but I am projecting with that query, so GetResults() works OK.

however I am having real problems with getting results for the correct stuff.

we have quite a large number of page types (too many), all inheriting from a BasePage, but all with different content areas/wysiwyg properties. and I would like to return hits from all of them.

it seems the only way to do that is to search on SearchText(), but I am finding this is problematic

wildcard searches seem to highlight much more than the search term.
finding a way to avoid header/footer/nav parts of the page using the SearchText() property

not sure if I should forget about typesearching and use unified search, but seems like I would have to do a lot of work setting up the ISearchContent on each type I want a result on.

#270112
Jan 17, 2022 11:56
Vote:
 

Hi Nat,

You can include a properties content in the index by decorating the property with the [Searchable] attribute, you can also exclude properties from content items by decorating them with [JsonIgnore] attribute.  It's worthwhile seeing if this helps you with relevancy of content.  You could potentially test it with a single content type, trigger a single document to be updated in the index and then compare what is stored in the index by going to the explore screen in the Find interface in the CMS backend.

#270113
Jan 17, 2022 12:20
* 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.