This page contains descriptions of all character types. Character types differ in how characters of these types are indexed. The type of each character is specified in the alphabet of an index, which is described by the Alphabet class. Character types are represented by the CharacterType enumeration: SEPARATOR, LETTER, BLENDED and SEPARATE_WORD. For more information on managing the alphabet, see the Alphabet page in the Managing dictionaries section.
The alphabet defines how the text of documents is divided into words, so it can be changed only while the index contains no documents and is not performing an operation. Otherwise, a method that changes the alphabet raises RuntimeError. Therefore, configure the alphabet after creating a new index and before adding the first document, as the examples below do. To use another alphabet with documents that are already indexed, create a new index and index the documents again. See the Index format and compatibility page for details.
Regular characters
Regular characters are separators and letters. During indexing, separators are used to separate words from each other, and words are formed from continuous sequences of letters.
The type of each particular character can be specified in the alphabet. By default, the following characters are defined as letters (Unicode code points are given):
Digits: 0030-0039;
Latin capital letters: 0041-005A;
Low line: 005F;
Latin small letters: 0061-007A;
Latin letters: 00C0-00D6, 00D8-00F6, 00F8-00FF, 0100-017F, 0180-024F, 0250-02AF;
Arabic letters: 0610-061A, 0620-0669, 066E-06D3, 06D5-06DC, 06DF-06E8, 06EA-06FC, 06FF, 0750-077F, 0870-0887, 0889-088E, 0898-089F, 08A0-08E1, 08E3-08FF, FB50-FBB1, FBD3-FD3D, FD50-FD8F, FD92-FDC7, FDF0-FDFB, FE70-FE74, FE76-FEFC, 10EFD-10EFF, as well as the letters of the Arabic Mathematical Alphabetic Symbols block (1EE00-1EEBB).
The other characters are defined as separators in the alphabet.
The following example demonstrates how to specify only digits, the low line character, and English letters as letters in the alphabet.
fromgroupdocs.searchimportIndexfromgroupdocs.search.dictionariesimportCharacterType# Creating a new index in the specified folder# The alphabet can be changed only while the index contains no documentsindex=Index("./index",True)# Configuring the alphabet# Setting the separator type for all characters in the alphabetindex.dictionaries.alphabet.clear()# Creating a list of letter characterscharacters=[]forcode_pointinrange(0x0030,0x0039+1):characters.append(chr(code_point))# Digitsforcode_pointinrange(0x0041,0x005A+1):characters.append(chr(code_point))# Latin capital letterscharacters.append(chr(0x005F))# Low lineforcode_pointinrange(0x0061,0x007A+1):characters.append(chr(code_point))# Latin small letters# Setting the type of characters in the alphabetindex.dictionaries.alphabet.set_range(characters,CharacterType.LETTER)# Indexing documents from the specified folderindex.add("./documents")# Searching in the indexresult=index.search("Einstein")print("Documents found:",result.document_count)
The set_range method also takes a list of Unicode code points (integers), which allows you to specify characters outside the Basic Multilingual Plane, for example index.dictionaries.alphabet.set_range([0x1D538], CharacterType.LETTER). A list of one-character strings works too, and such a string may hold a character outside the Basic Multilingual Plane: set_range(["\U0001D538"], CharacterType.LETTER).
Blended characters
Blended characters are special characters that are indexed both as separators and as letters. This type of character can be useful, for example, for indexing hyphens. In this case, parts of a compound word containing a hyphen will be indexed both as a single word with a hyphen and individually without a hyphen. An example of using blended characters is presented below.
fromgroupdocs.searchimportIndexfromgroupdocs.search.dictionariesimportCharacterType# Creating a new index in the specified folderindex=Index("./index",True)# Setting hyphen character type to blendedindex.dictionaries.alphabet.set_range(["-"],CharacterType.BLENDED)# Indexing documents from the specified folderindex.add("./documents")# Searching in the indexresult1=index.search("Elliot-Murray-Kynynmound")result2=index.search("Elliot")result3=index.search("Murray")result4=index.search("Kynynmound")forquery,resultin[("Elliot-Murray-Kynynmound",result1),("Elliot",result2),("Murray",result3),("Kynynmound",result4)]:print(query+":",result.document_count,"document(s)")
A sequence of blended characters without letters, for example a standalone hyphen, also forms a term. By default, such terms are not indexed, because the skip_blended_only_terms index setting is enabled. To keep them in the index, disable this setting when creating the index (see Search index settings).
Indexing each character as a whole word
Another special type of character is a character indexed as a separate word, the SEPARATE_WORD value of the CharacterType enumeration. This type of character is designed to work with hieroglyphic languages and allows you to index each such character in the text as a separate word, regardless of the presence of separators. By default, no characters of this type are defined in the alphabet. As an alternative for such languages, you can split text into words with an external library, see the Custom text segmenter page.
The following example demonstrates how to index each CJK unified ideograph as a separate word.
fromgroupdocs.searchimportIndexfromgroupdocs.search.dictionariesimportCharacterType# Creating a new index in the specified folderindex=Index("./index",True)# Setting the separate word type for the CJK unified ideographscharacters=[chr(code_point)forcode_pointinrange(0x4E00,0x9FFF+1)]index.dictionaries.alphabet.set_range(characters,CharacterType.SEPARATE_WORD)# Indexing documents from the specified folderindex.add("./documents")# Searching in the index for a single characterresult=index.search("书")print("Documents found:",result.document_count)print("Occurrences found:",result.occurrence_count)
Along with the full-featured library, we provide a free online document search app. You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our Free Online Document Search App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.