I am novice in Solr. I want to build a documents just like below.
{
id : "what"
count : "123"
},
{
id : "what is"
count : "134"
}
Here. I used id as term(string) which will be unique values. If I do indexing and searching on id. Will it reduce the speed* of searching in Solr or it is not a better way to make id as default search. Any suggestion please ?
No, it will not have any real impact - as long as the field is actually defined as a StrField.
You should not have a unique id field that is defined as a TextField and where there are several filters and tokenizers applied.
Whether it's the default search field or not does not matter performance wise, just what field q=what is will be matched against.
Related
I am creating an index in Azure Search Service and looking for a way to allow unknown fileds to be submitted. My documents are semi structured, meaning I know few fields up front. But I want the flexibility to be able to add documents with additional fields.
for example:
{
"name":"name1",
"description":"description"
"unknown,_simple":"test",
"unknown_complex": [{
"male":20,
"female":30
}]
}
In the above example, I know about Name and Description fields so they are added to the index with correct mapping. But unknow_simple and unknown_complex types are not know. Users can submit these when they are creating the documents. Right now Azure Search Rest API is complaining with the following error message
The request is invalid. Details: parameters : A resource without a
type name was found, but no expected type was specified. To allow
entries without type information, the expected type must also be
specified when the model is specified
How can I achieve this? Thank you for you help.
Per my understanding , you want to design your index designed as semi structured , "name" and "description" are two fixed fields and with fixed data type. There will be two flexible fields that you are not sure about its data type. In fact, you can define its data type as string.
Let's say you want to store a json object in that filed, just stringizing your json object so that you can set this string value in that field. Converting this value to json when next time you need it .
If you want to query certain field of json object in your Dynamic field, you can just use the json string fragment as query key to search , just as below :
Lets assume that "Description" filed is my Dynamic field and its value is a json string , I can use the key fragment to get result I want. But it is not so elegant though .
I have to use a field "manufacturerName" for both solr search and solr facet in Hybris. While the solr free text search requires the field type to be text, the facet only works properly in string type.
Is there any way to use this same field for both search and facet. I think there is one way by using "copyField" but I searched a lot, and still don't know how to use it?
Any help would be highly appreciated!
PS: On keeping the field type string, free text search doesn't fetch proper results. On keeping the field type text, facet shows truncated values.
Using a copyField instruction is the way to go, but that require you to define an alternative field - meaning you have one field with the type text and the associated tokenization, and one field of the type string which isn't processed in any way. There is no way in Solr to combine these in a single field that I know of.
You'll then use the name of the string field to generate the facets, while you use the other field when you're querying.
<copyField source="text_search_field" dest="string_facet_field" />
You'll then have to refer to the name string_facet_field when you're filtering or faceting on the field. You'll want to filter against the facet field after the user selects a facet, since you otherwise would end up with documents from other facets possibly leaking into your document result set (for example if the facet was "Foo Bar", you'd suddenly get documents that had "Baz Foo Bar Spam" as the facet, since both words are present in the search string.
I was not able to implement the "copyField" approach, but I found another easy way to do this. In solr.impex, I had already added my new field manufacturerNameFacet of type string, but there is a parameter "fieldValueProvider" and "valueProviderParameter". I provided these values as "springELValueProvider" and the field I wanted to use for search and facet "manufacturerName". After a solr full indexing, it worked like a charm. No other setting was required. The search and facet both were working as expected.
In the Mongoose documentation there is this little snippet:
Person
.find({ occupation: /host/ })
.where('name.last').equals('Ghost')
.where('age').gt(17).lt(66)
.where('likes').in(['vaporizing', 'talking'])
.limit(10)
.sort('-occupation')
.select('name occupation')
.exec(callback);
I am having a hard time understanding what the .find({ occupation: /host/ }) does different than the .select('name occupation'). Does find add conditions like where? or does it control the fields returned?
UPDATE
Ok, so i see that select only controls the fields from the final result of the queries, but now I do not understand how Find and Where are different. Am I not able to create the same queries using Find and using Where? Is the following snippet the same?
Person
.where('occupation').equals('host')
.where('name.last').equals('Ghost')
.where('age').gt(17).lt(66)
.where('likes').in(['vaporizing', 'talking'])
.limit(10)
.sort('-occupation')
.select('name occupation')
.exec(callback);
From the API docs on select:
Query#select(arg)
Specifies which document fields to include or exclude
.select('name occupation') says that results should only include the name and occupation fields. You do not wish to see any other fields in your results.
find describes which documents to include in the results. select indicates which fields of those documents should be visible in the results.
find is the actual query. In this example you are getting all rows that have occupation equal to host. Now each of the object that matches that query has several attributes. Lets assume it has the attributes name, age, email and occupation. When you specify that you want to select name and occupation you say that you just want those attributes. So in our case age and email will not be sent back from the query.
where in this case is used to specify more than one constraint against which to query. Usually, where is used because it provides greater flexibility than find such as passing in javascript expressions
Problem:
I have a movie information in solr. Two string fields define the movie title and director name. A copy field define another field which solr search for default.
I would like to have google like search with limited scope as follows. How to achieve it.
1)How to search solr for contains
E.g.
a) If the movie director name is "John Cream", searching for joh won't return anything. However, searchign for John return the correct result.
b) If there is a movie title called aaabbb and another one called aaa, searching for aaa returns only one result. I need to return the both results.
2) How to account for misspelling
E.g.
If the movie director name is "John Cream", searching for Jon returns no results. Is there a good sounds like (soundex) implementation for solr. If so how to enable it?
You can use solr query syntax
Searching for contains is obviously possible using wildcards (eg: title:*aaa* will match 'aaabbb' and also 'cccaaabbb'), but be careful about it, becouse it doesn't use indexes efficently. Do you really need this?
A soundex like search is possible applying solr.PhoneticFilterFactory filter to both your index and query. To achieve this define your fieldType like this in schema:
<fieldType name="text_soundex" class="solr.TextField">
...
<filter class="solr.PhoneticFilterFactory" encoder="Soundex" inject="true"/>
</fieldType>
If you define your "director" field as "text_soundex" you'll be able to search for "Jon" and find "John"
See http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters for more information.
Things you are asking, the first one is definitely achievable from Solr. I don't know about soundex.
1)How to search solr for contains
You can store data into string type of field or text type of field. In string field by wild card searching you can achieve the result (E.g field1:"John*"). Also you should look into different types of analyzers. But before everything, please look into the Solr reference http://wiki.apache.org/solr/.
def self.get_search_deals(search_q, per = 50)
data = Sunspot.search(Deal) do
fulltext '*'+search_q +'*', fields: :title
paginate page: page_no, per_page: per
end
data.results
end
searchable do
text :title
end
just pass string as "*sam*"
I'm trying to build auto suggest functionality using Solr. The index contains different locations within a city and looks something like
id: unique id
name: the complete name
type: can be one of 'location_zone', 'location_subzone', 'location_city', 'outlet', 'landmark' ...
city: city id
now when the user types something, I want it to return suggestion only from the current city and of type location_*. something similar to WHERE city_id = 1 AND type="location_%" in SQL.
I guess one way to do it is by faceting but is that the right way? will it still search in all documents and then filter the results or will it apply the condition first as mysql would do it
PS: I'm new to solr and would appreciate if you can point out any mistakes in the approach
Solr does provide filtering, using the fq parameter. What you're looking for should be something along the lines of:
&fq=city_id:1&fq=type:location_*&q=...
This page illustrates very well how and when to use filter queries in Solr.