クエリシンタックス | KandaSearch Community Support Forum

クエリシンタックス

トピック作成者:ks-solruserml-bot (2025/07/17 11:14 投稿)
3
OpenOpen

(The bot translated the original post https://lists.apache.org/thread/tfc0dylm21yy0260t8j5rf0g9vzgf7cn into Japanese and reposted it under Apache License 2.0. The copyright of posted content is held by the original poster.)

Solr 9.7.0 で次のような動作を確認しています:

値が空(未設定)の属性を検索するために、-attributename1:* という構文を使っています。
このクエリは正しく動作し、たくさんの結果が返ってきます(多くのドキュメントで attributename1 が空だからです):

http://hostname:8983/solr/solr1/select?q=-attributename1:*%20AND%20Class:Document&wt=xml&rows=10000

ところが、attributename1 または attributename2 のどちらかが空であるものを検索しようとすると、結果が0件になります:

http://hostname:8983/solr/solr1/select?q=-attributename1:*%20OR%20-attributename2:*%20AND%20Class:Document&wt=xml&rows=10000

最初の2つの属性を括弧で囲んでも動作は変わらず、やはり結果はゼロです:

http://hostname:8983/solr/solr1/select?q=(-attributename1:*%20OR%20-attributename2:*)%20AND%20Class:Document&wt=xml&rows=10000

なぜこのようなことが起きているのか、ご存じの方はいらっしゃいますか?
少なくとも attributename1 が空の結果は返ってくるはずだと思うのですが。

Henry Farmerie

返信投稿者:ks-solruserml-bot (2025/07/17 11:14 投稿)

こんにちは、

これは Lucene における「純粋な否定クエリ(pure negative query)」の端的なケースに該当します。
Google で検索してみると、いくつか関連記事が見つかると思います。

クエリはもっと明示的に書き直してみてください。たとえば以下のように:

q=(*:* -attributename1:*) OR (*:* -attributename2:*) AND Class:Document

Jan

返信投稿者:ks-solruserml-bot (2025/07/17 11:14 投稿)

ありがとうございます。そのクエリでちゃんと動きました!

返信投稿者:ks-solruserml-bot (2025/07/17 11:15 投稿)

これはブール検索における「純粋な否定クエリの罠」です。
さらに厄介なのは、あるケースでは正しく処理されるのに、他のケースではそのまま通ってしまうことです。

--
よろしくお願いします、
Mikhail Khludnev

トピックへ返信するには、ログインが必要です。

KandaSearch

Copyright © 2006-2025 RONDHUIT Co, Ltd. All Rights Reserved.

投稿の削除

この投稿を削除します。よろしいですか?