How Does Spotlight Work?
Spotlight provides fast desktop searching by extracting metadata in the background and storing the indexed metadata for future searches. When a query is made, the indexed metadata is searched for matching files.
Extracting Metadata from Files
Every time a file is created, modified or deleted, the kernel notifies the Spotlight engine that it needs to update the system store for changed file. Using Launch Services, Spotlight determines the uniform type identifier of the file and attempts to find an appropriate importer plug-in. If an importer exists and is authorized, it is loaded and passed the path to the file.
Figure 1 Extracting Metadata
Extracting Metadata
It is the importer’s responsibility to then read the data file and construct a dictionary that contains the appropriate metadata. When finished extracting the metadata, the dictionary is returned to the Spotlight engine, which then updates the system store.
Querying Spotlight for Metadata
Spotlight queries are made by client applications, such as the Finder. The application constructs the appropriate query expression for the search, specifies the scope of the search, how the data is to be grouped when it is returned, and then executes the query. The query is passed to the Spotlight engine, which begins the initial result-gathering phase of the search. During this phase the system store is searched for metadata that matches the query, and it returns the search results to the application.
Figure 2 Querying Spotlight
Querying Spotlight
If the query is configured to return live-update results, Spotlight notifies the client application when a change to the system store is made that causes the search results to change. Changes to the system store can cause additional files to match the query or cause files that initially matched to no longer match the query. Spotlight notifies the client application of the type of change, and the client application can update its results as appropriate.
Spotlightは、バックグラウンドでメタデータを抽出し、将来の検索のためにインデックス化されたメタデータを保存することで、高速なデスクトップ検索を実現します。クエリを実行すると、インデックス化されたメタデータが検索され、一致するファイルが見つかります。
ファイルからメタデータを抽出する
ファイルが作成、変更、削除されるたびに、カーネルはSpotlightエンジンに、変更されたファイルのシステムストアを更新する必要があることを通知します。Launch Servicesを使用して、Spotlightはファイルのユニフォームタイプ識別子を決定し、適切なインポータープラグインを見つけようとします。インポーターが存在し、許可されている場合、それがロードされ、ファイルへのパスが渡されます。
図 1 メタデータの抽出
メタデータの抽出
次にデータファイルを読み込んで、適切なメタデータを含む辞書を構築するのは、インポーターの責任です。メタデータの抽出が終了すると、ディクショナリはSpotlightエンジンに返され、システムストアが更新されます。
Spotlightによるメタデータのクエリ
Spotlight のクエリは、Finder などのクライアント アプリケーションによって実行されます。アプリケーションは、検索に適したクエリ式を構築し、検索の範囲と、データが返されたときにどのようにグループ化するかを指定し、クエリを実行します。クエリーは Spotlight エンジンに渡され、検索の最初の結果収集フェーズが開始されます。この段階で、システムストアからクエリに一致するメタデータが検索され、その結果がアプリケーションに返される。
図2 Spotlightの検索
スポットライトのクエリ
クエリがライブアップデートの結果を返すように設定されている場合、Spotlight は、検索結果を変更させるようなシステムストアの変更が行われたときに、クライアントアプリケーションに通知します。システム ストアの変更により、クエリに一致するファイルが追加されたり、最初に一致したファイルがクエリに一致しなくなったりすることがあります。Spotlightは変更の種類をクライアントアプリケーションに通知し、クライアントアプリケーションは適切に結果を更新することができます。

コメント