Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Search fluent api concept intro#271

Closed
koltyakov wants to merge 3 commits intoSharePoint:devfrom
koltyakov:dev
Closed

Search fluent api concept intro#271
koltyakov wants to merge 3 commits intoSharePoint:devfrom
koltyakov:dev

Conversation

@koltyakov
Copy link
Copy Markdown
Collaborator

Q A
Bug fix? [ ]
New feature? [x]
New sample? [x]
Related issues? mentioned in #207

What's in this Pull Request?

This PR introduces the concept which allows adding some fluent wrapper to search API, such as startRow, rowLimit, pageNum options for search queryable instance.

Guidance

search method in Rest class returns SearchResults promise, which prevents adding any additional options to a query in a fluent way.
An alternative approach is applied - searchAdv method is added to Rest class.
searchAdv returns Search object, allowing to define additional properties in a chain before actual execute.

Examples

Skipping results, defining results amount on a page

var query = "*"; // or SearchQuery interface { Querytext: "*", ... }
$pnp.sp.searchAdv(query)
     .startRow(3) // An equivalent of providing StartRow property in SearchQuery options
     .rowLimit(7) // An equivalent of providing RowLimit property in SearchQuery options
     .execute().then(function(res) { 
           // Results of a search query processing
           // Will return 7 search results, 3 rows will be skipped
     });

Pagination helper

var query = "*"; // or SearchQuery interface { Querytext: "*", ... }
$pnp.sp.searchAdv(query)
     // .rowLimit(15) // An equivalent of providing RowLimit property in SearchQuery options
     // When RowLimit is omited and pageNum is used a default value of 10 for RowLimit is used.
     // When pageNum is used StartRow setting declaration is ignored, value of StartRow is calculated automatically based on pageNum and RowLimit values. 
     .pageNum(2)
     .execute().then(function(res) { 
           // Results of a search query processing
           // Will return 10 search results, 10 rows will be skipped, showing a content for "2nd page"
     });

@msftclas
Copy link
Copy Markdown

Hi @koltyakov, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by Microsoft and real humans are currently evaluating your PR.

TTYL, MSBOT;

@koltyakov
Copy link
Copy Markdown
Collaborator Author

Hi Patrick (@patrick-rodgers),

There was an issue #207 sometime before, asking how to use pagination with search results.
I've decided to implement an alternative way to get pagination capability helper, which, I hope, is close to the vision of PnP-JS-Core. It's a working concept. I'm not totally sure about naming convention, but, in any case, I consider having an option defining some search request properties and calc some of them helpful.

Could you please take a look, is it ok with a whole structure of a library. Thanks!

@patrick-rodgers
Copy link
Copy Markdown
Contributor

@koltyakov - sorry been slammed, will be looking at this hopefully this week but like what I see initially. I need to pull it down and really have a look - but didn't want you to think I'm ignoring the PR :)


// Used with alternative search
if (typeof query === "undefined" && typeof this.searchQuery !== "undefined") {
if (typeof this.pageNumValue !== "undefined") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the defaults here match the OOB defaults when hitting the search endpoint without specifying values?

@johnnliu
Copy link
Copy Markdown
Contributor

johnnliu commented Feb 22, 2017

What about a slightly different syntax?

$pnp.sp.search(query)  // same as before
     .startRow(3) // An equivalent of providing StartRow property in SearchQuery options
     .rowLimit(7) // An equivalent of providing RowLimit property in SearchQuery options
     .asRows()  // add this, also .asRows<type>()
     .execute()

@patrick-rodgers
Copy link
Copy Markdown
Contributor

Going to close this - but I took a lot of the ideas and used them in #433. Have a look and let me know what you think there. Will also be pushing these updates out in a beta shortly so folks can try it out and provide feedback.

@koltyakov
Copy link
Copy Markdown
Collaborator Author

Thanks Patrick, SearchQueryBuilder thing looks gracefully!

@koltyakov koltyakov deleted the dev branch September 6, 2017 06:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants