I'm highlighting unnecessary word for example I'm search for "Document CASE No. 2015-331"
here the list that searchkick will highlight
"Document CASE No. 2015-331"
"Not"
"no"
"on"
"case is"<----- this is very weird i dont know why this is
highlighted lol
"2015"
"2017"
"2018"
"2016"
"to"
"Not to"
here's what's my search looks like
search = ::Document.search params[:q], fields: [:content], where: {id:
params[:id]}, highlight: { tag: 'span class=match-matcher',
fragment_size: #document.content.length}
search.with_highlights.each do |document, highlights|
document.content = highlights[:content]
end
the goal here to highlight the "Document CASE No. 2015-331" only
Looks like your field has been analyzed when indexed.
If you want to achieve the exact match and tokens should be searchable the mapping should be "not_analyzed" and the data needs to be re-indexed.
Here you are looking for exact match.
Modify the mapping for you field by adding something like below.
"mappings": {
"properties": {
"city": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
Related
I have a JSON that looks something like this:
{
...
"names": [
{
"value": "Name",
"language": "en"
}
],
"descriptions": [
{
"value": "Sample description",
"language" "en"
}
],
...
}
When using JsonProvider from the FSharp.Data library, it maps both fields as the same type MyJsonProvider.Name. This is a little confusing when working with the code. Is there any way how to rename the type to MyJsonProvider.NameOrDescription? I have read that this is possible for the CsvProvider, but typing
JsonProvider<"./Resources/sample.json", Schema="Name->NameOrDescription">
results in an error.
Also, is it possible to define that the Description field is actually an Option<MyJsonProvider.NameOrDescription>? Or do I just have to define the JSON twice, once with all possible values and the second time just with mandatory values?
[
{
...
"names": [
{
"value": "Name",
"language": "en"
}
],
"descriptions": [
{
"value": "Sample description",
"language" "en"
}
],
...
},
{
...
"names": [
{
"value": "Name",
"language": "en"
}
],
...
}
]
To answer your first question, I do not think there is a way of specifying such renaming. It would be quite reasonable option, but the JSON provider could also be more clever when generating names here (it knows that the type can represent Name or Description, so it could generate a name with Or based on those).
As a hack, you could add an unusued field with the right name:
type A = JsonProvider<"""{
"do not use": { "value_with_langauge": {"value":"A", "language":"A"} },
"names": [ {"value":"A", "language":"A"} ],
"descriptions": [ {"value":"A", "language":"A"} ]
}""">
To answer your second question - your names and descriptions fields are already arrays, i.e. ValueWithLanguge[]. For this, you do not need an optional value. If they are not present, the provider will simply give you an empty array.
I have requirement to get the optgroup of selected field in the query builder, but as of I am aware queryBuilder('getRules') doesn't provide. For example:- I want to get optgroups object of selected field 'price' in the json output. How to get it? Please give some idea.
-optgroups object
optgroups: {
core: {
en: 'Item'
}
}
-json output object
{
"condition": "AND",
"rules": [
{
"id": "price",
"field": "price",
"type": "double",
"input": "text",
"operator": "less",
"value": "10.25"
}
]
}
As I was answered for this question on GitHub by the library developer(#mistic100). The answer is-
You can use the data property of the filter https://querybuilder.js.org/index.html#filters
It will be copied as it on each rule using the said filter.
So I've been looking into the surveymonkey v3 api documentation for formatting questions types. What I want to do is create a multiple choice question that has an "other" option, which if selected has a text field that a user can fill in to be more specific. Is there a way to accomplish this with the api?
You should be able to do that when creating/updating a question.
Example:
POST /v3/surveys/<id>/pages/<id>/questions
{
"family": "single_choice",
"subtype": "vertical",
"answers": {
"other": [{
"text": "Other (please specify)",
"is_answer_choice": true,
"num_lines": 1,
"num_chars": 50
}],
"choices": [
{
"text": "Apples"
},
{
"text": "Oranges"
},
{
"text": "Bananas"
}
]
},
"headings": [
{
"heading": "What is your favourite fruit?"
}
]
}
This is_answer_choice field seems to not be accepted currently. That is a bug, you can watch the docs to potentially get notified on updates, or try it again later.
Edit: This method should work now, give it a try and let me know if it solves your problem!
I'm trying to document an API with a static swagger file that can return some JSON that contains an array that looks something like this:
[
{
"type": "type A",
"field A": "this field is specific to type A"
},
{
"type": "type B",
"field B": "this field is specific to type B"
}
]
I've tried a few different ways of defining my spec using either polymorphism or explicitly defining multiple examples. The examples have always either ended up looking like:
[
{
"type": "type A",
"field A": "this field is specific to type A",
"field B": "this field is specific to type B"
}
]
or just:
[
{
"type": "type A",
"field A": "this field is specific to type A"
}
]
Is there a way to define an example in my swagger spec so that the example payload shown by swagger-ui will contain an array containing an example of Type A and an example of Type B like the first JSON I wrote?
Actually, you can. In the responses object, put an examples object with an array as the value of the mime type. like so:
400:
description: Bad Request
examples:
application/json:
[
{
code:10000,
message:"Missing Input Parameters",
fieldA: "AAAAA"
},{
code:42,
message:"Ask the question",
fieldB: "BBBBBB"
}
]
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
You can't.
You can only define one example per mime-type per response :
{
"description": "A response",
"schema": {
"type": "string"
}
},
"examples": {
"application/json": {
"name": "Dog"
},
"application/xml": {
"name": "Cat"
}
}
}
If you want add complete scenario, I suggest you to write (or generate) a full scenario example in an HTML page and link it with an externalDocs. You can define externalDocs in root, operations, tags and schemas.
I'm using the elasticsearch-model gem for a model that has a has_many relationship. To match the documentation, let's say the model is Article and the relationship is has_many categories. So I wrote the customer serializer as follows (directly from the documentation):
def as_indexed_json(options={})
self.as_json(
include: { categories: { only: :title},
})
end
The serialization seems to work. The result of an example Article's as_indexed_json contains a "categories" => {"title"=> "one", "title"=> "two", "title"=> "three"} block.
What I'm struggling with, and haven't been able to find in the documentation, is how to search this nested field.
Here's what I've tried:
From the elasticsearch documentation on nested query I figured it ought to look like this:
r = Article.search query: {
nested: {
path: "categories",
query: {match: {title: "one"}}
}
}
but when I do r.results.first I get an error: nested object under path [categories] is not of nested type]...
I've tried adding changing the one line in the serializer to be: include: { categories: { type: "nested", only: :title} but that doesn't change anything, it still says that categories is not of a nested type.
Of course, I tried just querying the field without any nesting too like this:
r = Article.search query: {match: {categories: 'one'}}
But that just doesn't return any results.
Full text search like this:
r = Article.search query: {match: {_all: 'one'}}
Returns results, but of course I only want to search for 'one' in the categories field.
Any help would be much appreciated!
Rails don't create nesting mapping in elasticsearch. Elasticsearch is making the categories as object rather than nested child using dynamic mapping ("When Elasticsearch encounters a previously unknown field in a document, it uses dynamic mapping to determine the datatype for the field and automatically adds the new field to the type mapping as an object without nesting them"). For making them nested object you need to create mapping again in elasticsearch with categories as nested type, notice type as nested of category.
PUT /my_index
{
"mappings": {
"article": {
"properties": {
"categories": {
"type": "nested",
"properties": {
"name": { "type": "string" },
"comment": { "type": "string" },
"age": { "type": "short" },
"stars": { "type": "short" },
"date": { "type": "date" }
}
}
}
}
}
}
After this you can either reindex data from client or if you want zero downtime read here.
P.S: You have to delete the old mapping for particular index before creating a new one.
Ok, so it looks like: r = Article.search query: {match: {"categories.title" => 'one'}} works, but I'll leave the question open in case someone can explain what's going on with the nested thing...