Filter Algolia items based on a string attribute? [InstantSearch] - algolia

I'm trying to make a work around to a multi-language search different than this options, I have a field in my records 'language', I now I can filter based on a timestamp, i.e:
filters: 'timestamp < 1532681390'
But I cannot get this to work:
filters: 'language:en_us'
Am I missing somethign? Do I need to add language someplace else?

I just created an index per language as the docs say. :) Still open to suggestions.

Related

How to query from ListColumn[String] in cassandra using phantom

I am new to cassandra (started learning on my own interest few days back) and looking for help for the below problem.
I have a Cassandra table "User" and a ListColumn "interests extends ListColumn[String]".
Now, I want to fetch all users with an interest, say "playing".
like: select from user where interests.contains("playing")!
I scanned through the ListColumn api but not able to find any. Also, searched in google but no such helpful posts.
Any help guys please... Thanks in Advance :)
So there is contains among operators and here is an example how to use it. It looks like that it should work as any other operator, so just go for database.userTable.select.where(_.interests contains "playing").fetch() - of course, depending on your conventions.
This is possible with a secondary index on a collection column, which only works with a Set column, and not with a List.
Bottom line:
object interests extends SetColumn[String](this) with Index[Set[String]]
And then you can execute the following:
select.where(_.interests contains "test").fetch()
You can also use multiple restrictions if you allow filtering.
select.where(_.interests contains "test")
.and(_.interests contains "test2")
.allowFiltering()
.fetch()
The above will only match if both interests are found in a record.

Algolia Tags vs Facets Use Cases

New to Algolia, and having a bit of trouble deciphering the difference (suggested use) of tags vs. facets -- they seem to be functionally equivalent.
The Algolia documentation gives one example of a tag with a user ID -- e.g. "user_1234", which could then be used for filtering.
However that seems functionally equivalent to simply having this in your JSON:
"user": "1234"
and then declaring "user" as a faceted field.
What's the difference / purpose? Why have both tags and facets?
You're indeed correct that both can give you the same filtering functionality.
The main difference comes from facet counts that are computed at indexing time, which takes time.
That's why you can now add in your attributesForFaceting setting an onlyFilter modifier to your attribute, like so:
{
attributesForFaceting: [
'onlyFilter(user)'
]
}
This will tell the engine that the user attribute should be considered as a tag or tag list (this syntax is currently undocumented, but should soon be).
The same logic can be applied to numeric attributes. By default, the Algolia engine creates data structures for all numbers indexed in order to quickly answer to queries like nb_views>10000.
This is also computation-heavy, which is why you can add the equalOnly modifier in the numericAttributesToIndex.

Mysql to Sphinx query conversion

how can i write this query on sphinx select * from vehicle_details where make LIKE "%john%" OR id IN (1,2,3,4), can anyone help me? I've search a lot and i can't find the answer. please help
Well if you really want to use sphinx, could perhaps make id into a fake keyword, so can use it in the MATCH, eg
sql_query = SELECT id, CONCAT('id',id) as _id, make, description FROM ...
Now you have a id based keyword you can match on.
SELECT * FROM index WHERE MATCH('(#make *john*) | (#_id id1|id2|id3|id4)')
But do read up on sphinx keyword matching, as sphinx by default only matches whole words, you need to enable part word matching with wildcards, (eg with min_infix_len) so you can get close to a simple LIKE %..% match (which doesnt take into account words)
Actually pretty hard to do, becuase you mixing a string search (the LIKE which will be a MATCH) - with an attribute filter.
Would suggest two seperate queries, one to sphinx for the text filter. And the IN filter just do directly in database (mysql?). Merge the results in the application.

How to do a search by date query on cq pages

I am trying to create a blog in cq5. The OOTB search component in blog is not supporting search by date feature. I tried to override it, but could not find the correct query to fetch the blogs created on a particular date. Seems the only functions supported are >,>=,<,<=.
Please help me in finding a query (preferabbly xpath) to fetch a page created on a particular date (cq:lastModified).
There are some functions in XPath like contains or not. There is also one for date fields. Here an example for anything that was just modified in the content tree:
/jcr:root/content//*[#cq:lastModified >= xs:dateTime('2015-05-29T08:44:56.280Z')]

Finding similar posts with PostgreSQL

I have a table posts:
CREATE TABLE posts (
id serial primary key,
content text
);
When a user submits a post, how can I compare his post with the others and find similar posts?
I'm looking for something like StackOverflow does with the "Similar Questions".
While Text Search is an option it is not meant for this type of search primarily. The typical use case would be to find words in a document based on dictionaries and stemming, not to compare whole documents.
I am sure StackOverflow has put some smarts into the similarity search, as this is not a trivial matter.
You can get halfway decent results with the similarity function and operators provided by the pg_trgm module:
SELECT content, similarity(content, 'grand new title asking foo') AS sim_score
FROM posts
WHERE content % 'grand new title asking foo'
ORDER BY 2 DESC, content;
Be sure to have a GiST index on content for this.
But you'll probably have to do more. You could combine it with Text Search after identifying keywords in the new content ..
You need to use Full Text Search in Postgres.
http://www.postgresql.org/docs/9.1/static/textsearch-intro.html