Apache-solr-querying-data
提供:Dev Guides
Apache Solr-データのクエリ
データの保存に加えて、Apache Solrは必要に応じてデータを照会する機能も提供します。 Solrには特定のパラメーターが用意されており、これを使用して、保存されているデータを照会できます。
次の表に、Apache Solrで使用可能なさまざまなクエリパラメーターを示します。
Parameter | Description |
---|---|
q | This is the main query parameter of Apache Solr, documents are scored by their similarity to terms in this parameter. |
fq | This parameter represents the filter query of Apache Solr the restricts the result set to documents matching this filter. |
start | The start parameter represents the starting offsets for a page results the default value of this parameter is 0. |
rows | This parameter represents the number of the documents that are to be retrieved per page. The default value of this parameter is 10. |
sort | This parameter specifies the list of fields, separated by commas, based on which the results of the query is to be sorted. |
fl | This parameter specifies the list of the fields to return for each document in the result set. |
wt | This parameter represents the type of the response writer we wanted to view the result. |
これらすべてのパラメーターは、Apache Solrを照会するためのオプションとして表示できます。 Apache Solrのホームページにアクセスしてください。 ページの左側で、[クエリ]オプションをクリックします。 ここで、クエリのパラメーターのフィールドを確認できます。
レコードの取得
*my_core* という名前のコアに3つのレコードがあるとします。 選択したコアから特定のレコードを取得するには、特定のドキュメントのフィールドの名前と値のペアを渡す必要があります。 たとえば、フィールド *id* の値を持つレコードを取得する場合、フィールドの名前と値のペアをパラメーター *q* の値として- *Id:001* として渡し、実行する必要があります。クエリ。
同様に、次のスクリーンショットに示すように、 q を値としてパラメーター q に渡すことにより、インデックスからすべてのレコードを取得できます。
2 ^ nd ^レコードから取得する
次のスクリーンショットに示すように、パラメータとして start に値として2を渡すことにより、2番目のレコードからレコードを取得できます。
レコード数の制限
*rows* パラメーターに値を指定することにより、レコードの数を制限できます。 たとえば、次のスクリーンショットに示すように、パラメータ *rows* に値2を渡すことで、クエリの結果のレコードの総数を2に制限できます。
応答ライタタイプ
パラメーター wt の提供された値から1つを選択することにより、必要な文書タイプで応答を取得できます。
上記の例では、応答を取得するために .csv 形式を選択しました。
フィールドのリスト
結果のドキュメントに特定のフィールドを含める場合は、コンマで区切られた必須フィールドのリストを値としてプロパティ fl に渡す必要があります。
次の例では、フィールドを取得しようとしています-* id、phone、および *first_name 。