SharePoint Online Hub Search - How do you call the search API and limit results to content contained

%3CLINGO-SUB%20id%3D%22lingo-sub-799268%22%20slang%3D%22en-US%22%3ESharePoint%20Online%20Hub%20Search%20-%20How%20do%20you%20call%20the%20search%20API%20and%20limit%20results%20to%20content%20contained%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-799268%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20writing%20a%20web%20part%20that%20is%20surfacing%20all%20news%20pages%20on%20sites%20associated%20to%20a%20hub%20which%20have%20been%20tagged%20with%20a%20particular%20category%20(through%20page%20properties).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20do%20I%20limit%20the%20results%20of%20my%20call%20to%20the%20Search%20API%20to%20only%20include%20content%20from%20sites%20associated%20to%20the%20hub%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDo%20I%20have%20to%20first%20make%20calls%20to%20determine%20the%20sites%20associated%20to%20the%20hub%20(as%20per%26nbsp%3BMikael%20Svenson's%20post%3A%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fwww.techmikael.com%2F2018%2F04%2Fworking-with-hub-sites-and-search-api.html%22%20rel%3D%22nofollow%20noreferrer%20noopener%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fwww.techmikael.com%2F2018%2F04%2Fworking-with-hub-sites-and-search-api.html%3C%2FA%3E)%20and%20then%20use%20them%20in%20my%20query%20for%20news%20items%2C%20or%20is%20there%20an%20easier%20way%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20cannot%20see%20any%20%22Result%20Sources%22%20that%20have%20been%20created%20by%20creating%20the%20hub%2C%20and%20I%20don't%20really%20want%20to%20have%20to%20manually%20maintain%20one%20as%20sites%20are%20associated%2Fdisassociated%20to%20the%20hub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-799268%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EHub%20Site%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Esearch%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESearch%20API%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-799949%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Hub%20Search%20-%20How%20do%20you%20call%20the%20search%20API%20and%20limit%20results%20to%20content%20conta%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-799949%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F42656%22%20target%3D%22_blank%22%3E%40Nigel%20Witherdin%3C%2FA%3E%26nbsp%3BCheck%20out%20the%20Hub%20Site%20API.%3CBR%20%2F%3E%3CBR%20%2F%3EYou'll%20want%20to%20call%20%3CBR%20%2F%3E_api%2FHubsites%3Ffilter%3DSiteUrl%20eq%20%22%3CYOUR%20hubsite%3D%22%22%20url%3D%22%22%3E%22%3CBR%20%2F%3E%3CBR%20%2F%3EIt%20will%20return%20the%20ID.%20This%20ID%20you%20can%20use%20in%20your%20Search%20Query%20as%20the%20DepartmentId%20to%20search%20within%20your%20hub.%3C%2FYOUR%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

I am writing a web part that is surfacing all news pages on sites associated to a hub which have been tagged with a particular category (through page properties).

 

How do I limit the results of my call to the Search API to only include content from sites associated to the hub?

 

Do I have to first make calls to determine the sites associated to the hub (as per Mikael Svenson's post: https://www.techmikael.com/2018/04/working-with-hub-sites-and-search-api.html) and then use them in my query for news items, or is there an easier way?

 

I cannot see any "Result Sources" that have been created by creating the hub, and I don't really want to have to manually maintain one as sites are associated/disassociated to the hub

 

Thanks!

 

1 Reply

@Nigel Witherdin Check out the Hub Site API.

You'll want to call
_api/Hubsites?filter=SiteUrl eq "<Your hubsite url>"

It will return the ID. This ID you can use in your Search Query as the DepartmentId to search within your hub.