1

I have a requirement to makes an SPFX search webpart that can be searched by content type and also partial item url but it has to only return a specific content type from all sites accept root.

The content type is a list item and I'm using urldepth>1 to exclude root. However it returns no results when I try to search for site name or other parts of the url

I cant share all the code unfortunately due to the nature of the project.

Here it the basic query that the search object uses to generate the initial result set...

testQuery = "contentTypeId:0x0100BB00A852FB374E4FA11A71309A944B75* urldepth>1";
let _search: Search = new Search(this.props.wpContext.pageContext.web.absoluteUrl); 
let _results = await _search.execute({
      Querytext: testQuery,
      EnablePhonetic: true,
      TrimDuplicates: false,
      RowsPerPage: itemLimit,
      RowLimit: itemLimit,
      EnableSorting: true,
      StartRow: currentStartRow,
      SelectProperties: [ Constants.fieldName_Title, Constants.fieldName_SiteUrl, Constants.fieldName_ProjectStatus, Constants.fieldName_ProjectProposer, Constants.fieldName_Created, Constants.fieldName_SiteRelativeUrl ],
      SortList: [
        {
          'Property': Constants.fieldName_Created,
          'Direction': 1
        }
      ]   
    });

And in addition they can type into a text box to append keywords to the query. However it didnt work in the webpart so I took it to the modern search page to figure out if I'd made an error in my webpart somewhere

https://tenent.sharepoint.com/sites/testsite/_layouts/15/search.aspx?q="contentTypeId:0x0100BB00A852FB374E4FA11A71309A944B75* urldepth>1  project1"

This returns no results but when searched for separately it seems to work. I just cant seem to get them working togeather in a single query.

Appreciate any help you can give on this one.

Cheers!

1
  • Addition: sorry forgot to mention I'm using PNP JS (import { Web, Search } from '@pnp/sp';) and I following some more testing I dont think that by search in SharePoint modern search by a partial URL it doesn't return any results.
    – andy moore
    Jan 28, 2019 at 13:32

1 Answer 1

0

Just try to fill between filters AND:

https://tenant.sharepoint.com/sites/zvi/_layouts/15/osssearchresults.aspx#k=Title%3Dbatman%20AND%20ContentType%3ADocument#l=1029

enter image description here

2
  • 1
    Thanks this was correct and something i should have sheared was some of URLs i was search. Many of the sites contained hyphens which where being read as excludes. For this I lopped through the string and replaced hyphens with spaces. Thanks for your help!
    – andy moore
    Jan 30, 2019 at 11:47
  • You're welcome. Jan 30, 2019 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.