This page describes the creation of faceted search queries.
Faceted search definition
Faceted search within GroupDocs.Search is a filtering of search results by setting valid document field names to search.
Creating faceted search queries
Faceted search allows you to search only in certain fields of documents, for example, only in the content field or in the file name field. A simple faceted search example is presented below with queries in text and object form.
constindexFolder='c:/MyIndex/';constdocumentsFolder='c:/MyDocuments/';// Creating an index in the specified folder
constindex=newgroupdocs.search.Index(indexFolder);// Indexing documents from the specified folder
index.add(documentsFolder);// Search in the content field with text query
constquery1='content: Pellentesque';constresult1=index.search(query1);// Search in the content field with object query
constwordQuery=groupdocs.search.SearchQuery.createWordQuery('Pellentesque');constfieldQuery=groupdocs.search.SearchQuery.createFieldQuery(groupdocs.search.CommonFieldNames.Content,wordQuery,);constresult2=index.search(fieldQuery);
Faceted search can be combined with other types of searches using parentheses. The following faceted search example demonstrates the same multi-faceted search query in text and object form. Both queries search for documents in the name of which there are both the words “lorem” and “ipsum”, or the documents in the contents of which contain the phrase “lectus eu aliquam” or the phrase “dignissim turpis”.
constindexFolder='c:/MyIndex/';constdocumentsFolder='c:/MyDocuments/';// Creating an index in the specified folder
constindex=newgroupdocs.search.Index(indexFolder);// Indexing documents from the specified folder
index.add(documentsFolder);// Search with text query
constquery1='(filename: (lorem AND ipsum)) OR (content: ("lectus eu aliquam" OR "dignissim turpis"))';constresult1=index.search(query1);// Search with object query
constword6Query=groupdocs.search.SearchQuery.createWordQuery('lorem');constword7Query=groupdocs.search.SearchQuery.createWordQuery('ipsum');constandQuery=groupdocs.search.SearchQuery.createAndQuery(word6Query,word7Query);constfilenameQuery=groupdocs.search.SearchQuery.createFieldQuery(groupdocs.search.CommonFieldNames.FileName,andQuery,);constword1Query=groupdocs.search.SearchQuery.createWordQuery('lectus');constword2Query=groupdocs.search.SearchQuery.createWordQuery('eu');constword3Query=groupdocs.search.SearchQuery.createWordQuery('aliquam');constword4Query=groupdocs.search.SearchQuery.createWordQuery('dignissim');constword5Query=groupdocs.search.SearchQuery.createWordQuery('turpis');constphrase1Query=groupdocs.search.SearchQuery.createPhraseSearchQuery(word1Query,word2Query,word3Query);constphrase2Query=groupdocs.search.SearchQuery.createPhraseSearchQuery(word4Query,word5Query);constorQuery=groupdocs.search.SearchQuery.createOrQuery(phrase1Query,phrase2Query);constcontentQuery=groupdocs.search.SearchQuery.createFieldQuery(groupdocs.search.CommonFieldNames.Content,orQuery,);constrootQuery=groupdocs.search.SearchQuery.createOrQuery(filenameQuery,contentQuery);constresult2=index.search(rootQuery);
There are also fields that may be present in documents of any type. The names of such fields are represented in the CommonFieldNames class.
An example of using standard field names of documents is presented in the following example.
constindexFolder='c:/MyIndex/';constdocumentsFolder='c:/MyDocuments/';// Creating an index in the specified folder
constindex=newgroupdocs.search.Index(indexFolder);// Indexing documents from the specified folder
index.add(documentsFolder);// Search in the content field with text query
constquery1=groupdocs.search.WordsFieldNames.Company+": Dycum";constresult1=index.search(query1);// Search in the content field with object query
constwordQuery=groupdocs.search.SearchQuery.createWordQuery("Dycum");constfieldQuery=groupdocs.search.SearchQuery.createFieldQuery(groupdocs.search.WordsFieldNames.Company,wordQuery);constresult2=index.search(fieldQuery);
The following are the names of standard fields included in the library grouped by the formats containing them.
Common fields
Content
FileName
FormatFamily
CreationDate
ModificationDate
Epub format fields
Title
Subject
Author
Description
Language
Copyrights
Publisher
PublishedDate
Fiction Book format fields
Title
Subject
Keywords
Author
Description
Language
Publisher
PublishedDate
Mail format fields
MailMessageBody
MailSenderName
MailDisplayTo
MailSubject
Presentation format fields
Application
ApplicationVersion
Title
Subject
Comments
Keywords
ContentStatus
Category
Manager
Author
LastAuthor
Company
HyperlinkBase
CreatedTime
LastSavedTime
LastPrintedTime
RevisionNumber
TotalEditingTime
Spreadsheet format fields
Application
ApplicationVersion
Title
Subject
Comments
Keywords
ContentStatus
Category
Manager
Author
LastAuthor
Company
HyperlinkBase
CreatedTime
LastSavedTime
LastPrintedTime
Words format fields
Application
ApplicationVersion
Template
Title
Subject
Comments
Keywords
ContentStatus
Category
Manager
Author
LastAuthor
Company
HyperlinkBase
CreatedTime
LastSavedTime
LastPrintedTime
RevisionNumber
TotalEditingTime
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: