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.
C#
stringindexFolder=@"c:\MyIndex\";stringdocumentsFolder=@"c:\MyDocuments\";// Creating an index in the specified folderIndexindex=newIndex(indexFolder);// Indexing documents from the specified folderindex.Add(documentsFolder);// Search in the content field with text querySearchResultresult1=index.Search("content: Einstein");// Search in the content field with object querySearchQuerywordQuery=SearchQuery.CreateWordQuery("Einstein");SearchQueryfieldQuery=SearchQuery.CreateFieldQuery(CommonFieldNames.Content,wordQuery);SearchResultresult2=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 “Albert” and “Einstein”, or the documents in the contents of which contain the phrase “theory of relativity” or the phrase “special relativity”.
C#
stringindexFolder=@"c:\MyIndex\";stringdocumentsFolder=@"c:\MyDocuments\";// Creating an index in the specified folderIndexindex=newIndex(indexFolder);// Indexing documents from the specified folderindex.Add(documentsFolder);// Search with text querySearchResultresult1=index.Search("(filename: (Albert AND Einstein)) OR (content: (\"theory of relativity\" OR \"special relativity\"))");// Search with object querySearchQueryalbertQuery=SearchQuery.CreateWordQuery("Albert");SearchQueryeinsteinQuery=SearchQuery.CreateWordQuery("Einstein");SearchQueryandQuery=SearchQuery.CreateAndQuery(albertQuery,einsteinQuery);SearchQueryfilenameQuery=SearchQuery.CreateFieldQuery(CommonFieldNames.FileName,andQuery);SearchQuerytheoryQuery=SearchQuery.CreateWordQuery("theory");SearchQueryofQuery=SearchQuery.CreateWordQuery("of");SearchQueryrelativity1Query=SearchQuery.CreateWordQuery("relativity");SearchQueryspecialQuery=SearchQuery.CreateWordQuery("special");SearchQueryrelativity2Query=SearchQuery.CreateWordQuery("relativity");SearchQueryphrase1Query=SearchQuery.CreatePhraseSearchQuery(theoryQuery,ofQuery,relativity1Query);SearchQueryphrase2Query=SearchQuery.CreatePhraseSearchQuery(specialQuery,relativity2Query);SearchQueryorQuery=SearchQuery.CreateOrQuery(phrase1Query,phrase2Query);SearchQuerycontentQuery=SearchQuery.CreateFieldQuery(CommonFieldNames.Content,orQuery);SearchQueryrootQuery=SearchQuery.CreateOrQuery(filenameQuery,contentQuery);SearchResultresult2=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.
C#
stringindexFolder=@"c:\MyIndex\";stringdocumentsFolder=@"c:\MyDocuments\";// Creating an index in the specified folderIndexindex=newIndex(indexFolder);// Indexing documents from the specified folderindex.Add(documentsFolder);// Search in the content field with text querystringquery1=WordsFieldNames.Company+": Dycum";SearchResultresult1=index.Search(query1);// Search in the content field with object querySearchQuerywordQuery=SearchQuery.CreateWordQuery("Dycum");SearchQueryfieldQuery=SearchQuery.CreateFieldQuery(WordsFieldNames.Company,wordQuery);SearchResultresult2=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: