macos:Spotlight
出自UXGuide.net
Spotlight
Spotlight
Spotlight is a powerful Mac OS X search technology available to both users and application developers. Built on top of Search Kit and integrated with the file system, Spotlight makes searching for files on the computer as easy as searching the web. With Spotlight, users can search for things using attributes that have meaning for them, such as the intended audience for a document, the orientation of an image, or the key signature of the music in an audio file. Information like this (called metadata) is embedded in a file by the application that created it. Spotlight’s power comes from being able to extract, store, update, and organize the metadata of files to allow fast, comprehensive searches.
Spotlight是Mac OS X中功能强大的搜索技术,同时面向用户和程序开发者。Spotlight基于Search Kit并且和文件系统集成,从而使得在计算机上搜索文件和在互联网上搜索一样简单。通过Spotlight,用户可以根据对象内含的属性来搜索,例如文档的阅读者,图片的环境,或者音频文件中音乐的关键标志。这些信息(通常被称作元数据)被创建程序嵌入到文件中。Spotlight的强大就在于它能够抽取,保存,更新和管理这些文件中的元数据并提供快速的全面的搜索。
Spotlight is always available to users to help them find their files on the computer. Even better, the search technologies that power Spotlight are available to developers to help them find files to display, plug-ins to load, and data to use in their applications. For example, a developer can define complex queries to find only the types of files an application needs to work with or provide Spotlight functionality from within an application. The rest of this section introduces the user’s view of Spotlight and describes some of the ways an application can take advantage of its features.
用户总是可以使用Spotlight来在计算机上搜索文件。同时,开发者也可以利用Spotlight使用的搜索技术来寻找显示的文件,加载的插件以及在程序中使用的数据。例如,开发者可以定义复杂的查询条件来寻找程序支持的文件类型或者在程序中集成Spotlight的功能。本小节下面的内容从用户的角度介绍Spotlight并且介绍程序利用Spotlight技术的几种方式。
Users can easily initiate a Spotlight search using the Spotlight icon at the far right end of the menu bar. Figure 6-9 shows the Spotlight icon and search field displayed when a user clicks the icon.
U用户可以很方便的点击右上角菜单条上的Spotlight图标来开始Spotlight搜索。图6-9显示了Spotlight的图标和当用户点击图标时显示的搜索框。
Figure 6-9 The Spotlight icon and search field
图 6-9 Spotlight图标和搜索框
In addition, a user can select a word or phrase in a text document and Control-click to reveal a contextual menu that allows a Spotlight search for the selected text. Figure 6-10 shows this contextual menu.
此外,用户也可以在文本文档中选择一个单词或者短语并通过上下文菜单(Control+点击)来使用Spotlight搜索选定文字,如图6-10所示。
Figure 6-10 Spotlight search in a contextual menu
图 6-10 上下文菜单中的Spotlight搜索
Whichever way a search is initiated, Spotlight quickly displays the results, conveniently sorted into categories the user can adjust in Spotlight Preferences. Figure 6-11 shows the standard Spotlight results window.
无论通过哪种方式,Spotlight都会快速的显示结果,并且其结果会根据用户的Spotlight偏好设置排序,如图6-11所示。
Figure 6-11 A Spotlight results window
图 6-11 Spotlight搜索结果
Spotlight uses Quick Look technology to display thumbnails and full-size previews of the documents returned in a search. If your application produces documents in common content types, such as HTML, RTF, plain text, TIFF, PNG, JPEG, PDF, and QuickTime movies, Spotlight can display the thumbnails and previews automatically. If your application creates documents in an uncommon or custom content type, you can include a Quick Look generator to convert your native document format into a format Spotlight can display. See Quick Look Programming Guide to learn how to do this.
To applications, Spotlight provides almost limitless ability to find files and to give advanced file-search capabilities to users within the context of the application. For example, an application might choose to replicate the Spotlight contextual-menu item (shown in Figure 6-10) with a button that initiates a Spotlight search for the user’s selected text. The application could then display its own window that contains all the search results or a filtered subset of them.
对于应用程序来说,Spotlight提供了几乎无限制的寻找文件的能力并且在程序的上下文中给用户提供高级的文件搜索能力。例如,程序可能选择将Spotlight上下文菜单的菜单项移植到一个按钮上来搜索用户选定的文本。程序可以定制自己的窗口来显示所有的搜索结果或者过滤后的结果。
An application might also choose to give users access to Spotlight searches in a rounded search field (for more information on this control, see “Search Fields”). A user often needs to work on a file that was saved in an atypical place or given an unexpected or forgotten name. If an application offers only a Finder-based Open dialog, it might force the user to waste a lot of time navigating the file system, trying to remember what the file was named and where it was saved. Instead, an application can provide a Spotlight-powered search that allows the user to search the entire file system, using meaningful attributes other than the filename.
程序也可以提供一个搜索框并直接调用Spotlight的搜索功能(关于搜索框的更多信息,请参考 “搜索框”一节)。用户经常将文件保存在一个不常见的位置或者赋予文件一个不合适的文件名,或者忘记了文件名。如果程序仅提供基于Finder的打开文件的对话框,则可能使用户不得不浪费大量的时间在遍历文件系统中,并试图回忆起文件的名字以及保存的位置。如果程序能够提供Spotlight强大的搜索功能,用户则可以根据文件内含的有意义的属性而不是文件名搜索整个文件系统。
Applications can also use Spotlight functionality behind the scenes to find needed files or plug-ins. For example, an application that provides a back-up service might allow the user to choose a broad category of file type to back up, such as images. Instead of asking users to identify all the folders that contain their images or just backing up a Pictures folder, the application could perform a Spotlight search to find every image file in the file system, regardless of its location.
程序也可以在后台使用Spotlight功能来寻找需要的文件或者插件。例如,一个备份的程序允许用户选择某种类型的文件来进行备份,如图片。程序可以在后台进行Spotlight搜索来寻找文件系统的每个图片,而不是让用户指定含有图片的文件夹或者仅仅备份“图片”这个文件夹。 It’s important to emphasize that Spotlight is tuned to search for files; it’s not intended to do extensive text-based searching within a document. If you need to do fine-grained textual searching, you should use Search Kit technologies instead. An application that stores data in database records, for example, should not base its database search on Spotlight because the data are not stored in separate files. For more information on using Search Kit in your application, see Search Kit Programming Guide.
值得强调的是Spotlight是面向文件搜索,而不是在文档内部进行基于文本的搜索。如果您需要进行细粒度的文本搜索,您应该使用Search Kit技术。例如将数据保存在数据库记录中的程序不应将数据库搜索基于Spotlight,因为数据不是保存在各个独立的文件中的。关于在程序中使用Search Kit的更多信息请参考Search Kit编程指南。
Spotlight offers unparalleled search functionality to both users and developers. Along with these opportunities, however, comes an important developer responsibility. If your application uses a custom file format, you must supply a plug-in (called a Spotlight importer) that describes the types of metadata your file format contains. This ensures that a user will be able to search for the files your application creates using the attributes described by the metadata your files contain. For comprehensive information on how to do this, see Spotlight Importer Programming Guide.
Spotlight为用户和开发者都提供了强大的搜索功能。然而,随着机会的往往是挑战。如果您的程序使用了定制的文件格式,您必须提供一个插件(被称作Spotlight导入器)来描述您的文件格式的元数据,从而确保用户能够使用定制的文件格式的元数据描述的属性搜索到您的程序创建的文件。更多信息请参考Spotlight导入器编程指南。