How can you filter search by matching String to a field in Algolia? - filtering

I'm trying to create filters for a search on an Android app where a specific field in Algolia must exactly match the given String in order to come up as a hit. For example if Algolia has a field like "foo" and I only want to return hits where "foo" is equal to "bar", then I would expect that I would have to use a line of code like this:
query.setFilters("foo: \"bar\"");
Any guesses as to why this isn't working like I see in the examples or how to do so?

Ah, I thought that attributesForFaceting was done by setting what was searchable or not. It was on a different page within the dashboard than I was previously using. Thanks #pixelastic.

Related

Algolia search replace character

I use Algolia on my webpage. I have a product named 56x16 . When users search for 56*16 Algolia doesn't show results. How can I solve this problem?
Looks like the Algolia thinks that 56x16 is one word, but 65*16 are the two words. So, it is can't be matched. You can try to store this value as 56 x 16 to see results. Or you can store this value as different properties, something like { width:56, height:16 }
Also, you can read about typeTolerance property to load records with typos. You can read more about typoTolerance here

How to allow leading wild cards in custom smart search web part (Kentico 10)

I have a custom index for my products and I am using the Subset Analyzer. This Analyzer works great, but if you do field searches, it does not work.
For example, I have a document with the following fields:
"documentname", "My-Document-Name"
"tags", "1234,5678,9101"
"documentdescription", "This is a great Document, My-Document-Name."
When I just search "name AND tags:(1234)", I get this document in my results because it searches +_content:name.
-- However:
When I search "documentname:(name)^3.0 AND tags:(1234)", I do not get this document in my results.
Of course, when I do "documentname:(*name*)^3.0" I get a parse error saying: '*' or '?' not allowed as first character in WildcardQuery.
How can I either enable wildcard query in my custom CMS.Search webpart?
First of all you have to make sure that a field you checking is in the index with proper name. documentname might not be in the index it can be called _title, depends how you index is set up. Get lukeall and check your index (it should be in \CMS\App_Data\CMSModules\SmartSearch\YourIndexName). You can use luke to test your searches as well.
For examples there is no tags but there is documenttags field.
P.S. Wildcards are working and you are right you can't use them as a first character by default (lucene documentation says: You cannot use a * or ? symbol as the first character of a search), but there is a way to set it up in lucene.net, although i dont know if there are setting for that in Kentico. But i dont think you need wildcards, so your query should be (assuming you have documentname and documenttags in the index):
+(documentname:"My-Name" AND documenttags:"tag1")

Can a user exclude a keyword in search results?

For example, could they type "-Adventure" if they want results without the word adventure to appear in their search results?
Sure thing! You need to enable the advancedSyntax feature and then the - in front of words will be interpreted as a NOT.
index.search('Crazy -Adventure', { advancedSyntax: true }).then(...);
Will search all objects with Crazy and without Adventure.

AEM CQ5 Query Builder: How to get result by searching for 2 different values in same property?

I want to get result matches with all nodes contains property 'abc' value as 'xyz' or 'pqr'.
I am trying in below ways:
http://localhost:4502/bin/querybuilder.json?path=/content/campaigns/asd&property=abc&property.1_value=/%xyz/%&property.2_value=/%pqr/%property.operation=like&p.limit=-1&orderby:path
http://localhost:4502/bin/querybuilder.json?path=/content/campaigns/asd&property=abc&property.1_value=/%xyz/%&property.2_value=/%pqr/%&property.1_operation=like&property.2_operation=like&p.limit=-1&orderby:path
http://localhost:4502/bin/querybuilder.json?path=/content/campaigns/asd&1_property=abc&1_property.1_value=/%xyz/%&1_property.1_operation=like&2_property=abc&1_property.1_value=/%xyz/%&2_property.1_operation=like&p.limit=-1&orderby:path
But none of them served my purpose. Any thing that I am missing in this?
The query looks right and as such should work. However if it is just xyz or pqr you would like to match in the query, you may not need the / in the values.
For eg.
path=/content/campaigns/asd
path.self=true //In order to include the current path as well for searching
property=abc
property.1_value=%xyz%
property.2_value=%abc%
property.operation=like
p.limit=-1
Possible things which you can check
Check if the path that you are trying to search contains the desired nodes/properties.
Check if the property name that you are using is right.
If you want to match exact values, you can avoid using the like operator and remove the wild cards from the values.
You can actually use the 'OR' operator in your query to combine two or more values of a property.
For example in the query debug interface : http:///libs/cq/search/content/querydebug.html
path=/content/campaigns/asd
property=PROPERTY1
property.1_value=VALUE1
property.2_value=VALUE2
property.operation=OR
p.limit=-1
It worked with below query:
http://localhost:4502/bin/querybuilder.json?orderby=path
&p.limit=-1
&path=/content/campaigns
&property=jcr:content/par/nodeName/xyz
&property.1_value=pqr
&property.2_value=%abc%
&property.operation=like
&type=cq:Page
Note: property name should be fully specified form the type of node we are expecting.
Ex: jcr:content/par/nodeName/xyz above instead of just xyz

Mongoid, find object by searching by part of the Id?

I want to be able to search for my objects by searching for the last 4 characters of the id. How can I do that?
Book.where(_id: params[:q])
Where the param would be something like a3f4, and in this case the actual id for the object that I want to be found would be:
bc313c1f5053b66121a8a3f4
Notice the last for characters are what we searched for. How can I search for just "part" of my objects id? instead of having my user search manually by typing in the entire id?
I found in MongoDB's help docs, that I can provide a regex:
db.x.find({someId : {$regex : "123\\[456\\]"}}) // use "\\" to escape
Is there a way for me to search using the regular mongo ruby driver and not using Mongoid?
Usually, in Mongoid you can search with a regexp like you normally would with a string in your call to where() ie:
Book.where(:title => /^Alice/) # returns all books with titles starting with 'Alice'
However this doesn't work in your case, because the _id field is not stored as a string, but as an ObjectID. However, you could add (and index) a field on your models which could provide this functionality for you, which you can populate in an after_create callback.
<shameless_plug>
Alternatively, if you're just looking for a shorter solution to the default Mongoid IDs, I could suggest something like mongoid_token which makes it pretty easy to add shorter tokens/ids to your Mongoid documents.
</shameless_plug>