0

これが私のタイヤセッティングです。

def self.search(params)
    tire.search(load: true, page: params[:page], per_page: 9) do 
      query do
        boolean do
          must { string params[:query], default_operator: "AND" } if params[:query].present?
          must { range :published, lte: Time.zone.now }
          must { term :post_type, params[:post_type] } if params[:post_type].present? 
        end
      end
      sort { by :created_at, "desc" } if params[:query].blank?
      facet "posttypes" do
        terms :post_type
      end
    end
  end   

    settings :analysis => {
      :filter  => {
        :ngram_filter => {
          :type => "nGram",
          :min_gram => 2,
          :max_gram => 12
        }
      },
      :analyzer => {
        :index_ngram_analyzer => {
          :type  => "custom",
          :tokenizer  => "standard",
          :filter  => ["lowercase", "ngram_filter"]
        },
        :search_ngram_analyzer => {
          :type  => "custom",
          :tokenizer  => "standard",
          :filter  => ["standard", "lowercase", "ngram_filter"]
        }
      }
    } do
    mapping do
      indexes :_id, index: :not_analyzed
      indexes :tags, :analyzer => 'keyword'
      indexes :published, type: 'date'
      indexes :created_at, type: 'date'
      [:title, :description, :post_type].each do |attribute|
        indexes attribute, :type => 'string', :index_analyzer => 'index_ngram_analyzer', :search_analyzer => 'search_ngram_analyzer'
      end
    end
  end

  def to_indexed_json
    {
      _id: _id,
      title: title,
      description: description,
      tags: tags,
      post_type: post_type,
      published: published,
      created_at: created_at
    }.to_json
  end

コロンだけを書くと、次のエラーが発生します

500 : {"error":"SearchPhaseExecutionException[Failed to execute phase [query], total failure; shardFailures {[r7kpljHrRbOPzjngca91Uw][posts][3]: SearchParseException[[posts][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"query_string\":{\"query\":\":\"}},\"filter\":{\"range\":{\"published\":{\"lte\":\"2013-03-09T12:51:43Z\"}}},\"size\":9}]]]; nested: QueryParsingException[[posts] Failed to parse query [:]]; nested: ParseException[Cannot parse ':': Encountered \" \":\" \": \"\" at line 1, column 0.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    \"*\" ...\n    ]; nested: ParseException[Encountered \" \":\" \": \"\" at line 1, column 0.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    \"*\" ...\n    ]; }{[r7kpljHrRbOPzjngca91Uw][posts][2]: SearchParseException[[posts][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"query_string\":{\"query\":\":\"}},\"filter\":{\"range\":{\"published\":{\"lte\":\"2013-03-09T12:51:43Z\"}}},\"size\":9}]]]; nested: QueryParsingException[[posts] Failed to parse query [:]]; nested: ParseException[Cannot parse ':': Encountered \" \":\" \": \"\" at line 1, column 0.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    \"*\" ...\n    ]; nested: ParseException[Encountered \" \":\" \": \"\" at line 1, column 0.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    \"*\" ...\n    ]; }{[r7kpljHrRbOPzjngca91Uw][posts][4]: SearchParseException[[posts][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"query_string\":{\"query\":\":\"}},\"filter\":{\"range\":{\"published\":{\"lte\":\"2013-03-09T12:51:43Z\"}}},\"size\":9}]]]; nested: QueryParsingException[[posts] Failed to parse query [:]]; nested: ParseException[Cannot parse ':': Encountered \" \":\" \": \"\" at line 1, column 0.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    \"*\" ...\n    ]; nested: ParseException[Encountered \" \":\" \": \"\" at line 1, column 0.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    \"*\" ...\n    ]; }]","status":500}

この問題をどのように修正しますか?

私はmongoid 3.xxでmongodbを使用しています

ありがとう!

4

3 に答える 3

1

lucene クエリの特殊文字はエスケープする必要があります。

\:の代わりに をクエリしてみてください:

于 2013-03-10T13:56:13.410 に答える
0

文字をエスケープするために、それを16進数に変換してみてください

于 2013-03-10T13:41:16.973 に答える