0

I am making simple SPFx search for SharePoint folders and files. How can I make search query that search results between start and end dates using QueryTemplate or Refiners properties?

return new Promise<ISearchResult[]>((resolve, reject) => {
        pnp.sp.search({
            Querytext: query,
            RowLimit: 20,
            StartRow: 0,
            QueryTemlate:'search query there',
            Refiners: 'search query there',
            SelectProperties: ["Title", "Author", "Path", "FileType","RefinersTextListOWSTEXT"]
        })
            .then((results) => {
                results.PrimarySearchResults.forEach((result) => {
                    _results.push({
                        title: result.Title,
                        description: result.HitHighlightedSummary,
                        link: result.Path,
                        author: result.Author,
                        filetype: result.FileType,
                        path: result.OriginalPath

                    });
                });
            })
            .then(
                () => { resolve(_results); }
            )
            .catch(
                () => { reject(new Error("Error")); }
            );
    });
0

1 Answer 1

0

Use query in QueryTemplate like:

QueryTemplate:"(LastModifiedTime>=2019-04-26 AND LastModifiedTime<=2022-11-03)"

Full code:

pnp.sp.search({
                Querytext: query,
                RowLimit: 20,
                StartRow: 0,
                QueryTemplate: "(LastModifiedTime >= " + stdate + " AND LastModifiedTime <= "+enddate+")",
                SelectProperties: ["Title", "Author", "Path", "FileType", "RefinersTextListOWSTEXT","ModifiedOWSDATE"]
            })

                .then((results) => {
                    results.PrimarySearchResults.forEach((result:any) => {
                        _results.push({
                            title: result.Title,
                            description: result.HitHighlightedSummary,
                            link: result.Path,
                            author: result.Author,
                            filetype: result.FileType,
                            path: result.OriginalPath,
                            culture: result.ModifiedOWSDATE
                        });
                    });
                })
                .then(
                    () => { resolve(_results); }
                )
                .catch(
                    () => { reject(new Error("Error")); }
                );

Your Answer

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

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