Reputation: 10744
This is my tire setting:
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
If I write only a colon : I get this error:
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}
How fix this problem?
I'm using mongodb with mongoid 3.x.x
Thanks!
Upvotes: 0
Views: 2238
Reputation: 25380
These special characters need escaping:
+ - && || ! ( ) { } [ ] ^ " ~ * ? : \
So you need \:
instead of :
Upvotes: 1
Reputation: 9049
Special characters in lucene queries need to be escaped.
Try querying for \:
instead of :
.
Upvotes: 1
Reputation: 993
try converting it to the Hex equivient to escape the character
Upvotes: 0