django 1.10 postgres full text search is not working - sql

I am trying to integrate full text search for django 1.10 with postgres database.
I am following tutorial from
https://docs.djangoproject.com/en/1.10/ref/contrib/postgres/search/
class Question(models.Model):
text = models.TextField(max_length=500)
ans = models.TextField(max_length=1500, blank=True)
I have several questions in the database which has the text 'for' in its text field for example: one question is:
text: what is best for me?
ans: this is best for you.
I am trying to make a query like
q = Question.objects.filter(text__search='for')
But this query is not returning any result. can anyone suggest me why?

It is actually my mistake. For Full text search when Postgres creates index it by default ignore common words like 'the', 'for', 'are','is' etc. So If you try to search using this keywords you search query will return empty even if there are lots of sentences with these words.
I did not know this. So I thought I misconfigured.

Related

Aem fulltextsearch

I want to search for a exact combination of words in all nodes in the aem using query builder.
Trying to debug the query http://localhost:4502/libs/cq/search/content/querydebug.html it returns me results that doesn't match my query.
For example if want to search for 'foo bar' in all nodes and I need to receive all nodes that contain 'Foo Bar', 'foo Bar', 'Foo bar', 'FOO BAR' but not only 'foo' and only 'bar' and not 'foo-bar'. Query in service is done by using QueryBuilder.
QueryBuilder is useful when you try to perform a query similar to SQL where you search against a property and its value. The full text search capabilities of the query debug interface is very limited as you have experienced.
However, remember that AEM uses an underlying Lucene and/or Solr index and it does provide a way to perform a native solr / lucene query.
Firstly create a embedded solr index (embedded is sufficient for a local development AEM instance) as mentioned under "Configuring AEM with an embedded SOLR server" in https://docs.adobe.com/docs/en/aem/6-0/deploy/upgrade/queries-and-indexing.html. This will trigger solr indexing of your JCR content.
Once indexing is complete (as seen from logs), you can perform native queries using the crx/de query interface.
Example query: select [jcr:path] from [nt:base] where native('solr', '<filter>?<solr_query_goes_here>'. Quite obviously you need to be familiar with solr queries. Thanks to the following slide share (slide 50 talks about native queries within AEM) http://www.slideshare.net/justinedelson/demystifying-oak-search
AEM support for native solr queries is a bit patchy. You might need to edit the SOLR schema xml file manually (created under the crx-quickstart folder) to add additional filters, custom fields etc. We had successfully tuned solr within AEM to perform a spacial search using the above method.
If you need all sorts of combinations for "foo bar" then you have to query:
fulltext=foo bar
You will only get the first 10 results. To get all, you'll need to:
p.limit=-1
You may want to specify the path:
path=/content/website/
Visit Adobe Query Builder API for more info.
Behind the scenes, AEM creates an xpath query and then executes it. Then, for any part of the query that doesn't map to xpath, it runs through the results and filters them.
You should also think about if there is a property to match as opposed to any text. That will give you much better results since you want accuracy. Right now you are casting an overly wide net, and I think you should consider restricting if for nothing other than performance reasons. Just a suggestion.
You say the results don't match your query, can you give us some idea of what comes back? And can you please put your actual query here. That will make it much easier to help.
this is a minimal example that provides a full-text search:
Query query = queryBuilder.createQuery(...);
// limit path
Predicate path = new Predicate(PathPredicateEvaluator.PATH);
path.set(PathPredicateEvaluator.PATH, "/content/where/ever);
query.getPredicates().add(path);
// Fulltext
Predicate fulltextSearch = new Predicate(FulltextPredicateEvaluator.FULLTEXT);
fulltextSearch.set(FulltextPredicateEvaluator.FULLTEXT, "foo bar");
fulltextSearch.set(FulltextPredicateEvaluator.REL_PATH, "jcr:content");
query.getPredicates().add(fulltextSearch);
// can I haz excerpt?
query.setExcerpt(true);
// Paging?
query.setStart(...);
query.setHitsPerPage(-1);
Note: it's not required to configure a solr index or whatever, you should be fine out of the box.
But if you limit the search to specific fields, you should create an index entry in oak:index. You can find a great cheat-sheet here.
I'm not sure if this helps.
but to get all the combinations of nodes that have the text i'm looking for I use jcr:like in xpath.
for example if I want to search all the nodes which has any property with Foo bar in its value or key, then my query looks like:
/jcr:root/content/yourpath//*[jcr:like(\*/, '%FOO bar%')]
You will not get that flexibility in QueryBuilder but you can still get what you want by using JCR-SQL2.
The following query will return all entries with "Foo Bar", "foo bar", "foo Bar", "Foo bar", but not "foo", "bar", "foo-bar" when your value is "foo bar".
SELECT * FROM [nt:unstructured] WHERE ISDESCENDANTNODE('/jcr:root/content/yourpath') AND LOWER([prop]) LIKE "%foo bar%" ORDER BY [cq:lastModified] desc
Just ensure that while checking for the values in repository you send the value in lowercase for case-insensitive search.
For case-sensitive search you can use:
SELECT * FROM [nt:unstructured] WHERE ISDESCENDANTNODE('/jcr:root/content/yourpath') AND [prop] LIKE "%foo bar%" ORDER BY [cq:lastModified] desc

Create custom advance search filter in CGridView in YII

I have a model which contains emails with some other fields.
I want a custom filter in Yii CGridView's advance search which when applied, lists only Invalid Email IDs (using regular expression '^[A-Z0-9._%-]+#[A-Z0-9.-]+\.[A-Z]{2,4}$')
Note: I dont want to add any column in CGridView
I hope to help you out,
you will need several things
the line for filtering in the column of your choice...(i recommend you create a new attribute for this, ask me in comments if you want to know more why.) this goes in the cgridview of course:
'filter'=>CHtml::activeCheckBox($model, $attributeEmail)
the condition in your search of function that brings up the model.
Supposing you have a criteria inside your search in your model wich help you with your filtering what you need is ...
if($this->EMAIL == TRUE)
{
$criteria->addCondition("\"t\".\"EMAIL\" email NOT LIKE '%_#__%.__%'");
}
Why not to use regex and make a KISS approach ? better read this first...
Sql script to find invalid email addresses
I'd be glad to hear your comments it is interesting question for yii dev's btw

Appcelerator Cloud Services - Find string in photos object custom field

I'm having trouble using the query/search capabilities of Cloud.photos, more specifically, finding a way of search for a string in title field.
After reading this: http://docs.appcelerator.com/cloud/latest/#!/guide/search_query, I was able to perform querys with $regex:
where: {title: {'$regex' : '^' + searchterm}},
But works only if the search term is in the beginning of the title, and it's case sensitive (I'm obviously a complete regex newbie).
Also tried search API with no luck. I didn't find which were the searchable fields.
So, I'm in some sort of dead end. I'm looking for a SQL like similar funcionality, where I can perform a search of a term and if matches regardless of the position and whether it is upper or lower case.
Thanks in advance.
see the release notes here for 11 Apr 2013
http://docs.appcelerator.com/cloud/latest/#!/guide/acs_releasenotes
it cannot be done any other way because the query would be too inefficient

Lotus Domino database FTSearch method and brackets

I need to search with FTSearch something like this - MS004790(419411/10). But it thorws NotesException: Notes error: Query is not understandable (MS004790(419411/10))
So maybe there is some trick to search strings like that or maybe I need to parse it somehow?
Tnx for help!
TL;DR: Wrap your search in quotes.
Full Text search has two modes. Web Search and Notes Search. In your notes preferences you can set this.
Web search is just like a text search. Notes search attempts to parse the search term.
However the client can fall back to Notes search terms if it sees the first characters are capitals (or capital reserved keywords like "FIELD"). So to prevent it from parsing you need to wrap it in quotes.
For example
(LotusScript)
searchString = |"MS004790(419411/10)"|
(Java)
searchString = "\"MS004790(419411/10)\""
If it is still failing after that, manually try the search in the FT search bar. Once you have that working the code should work the same way.
If it is still failing at that point it may be related to the UNK table. If so see the following:
Lotus Domino: After changing TYPE of a field, Full Text Search won't work for this field

Lucene search (How to query?)

I am trying to use Lucene full text search. And I cannot understand how to index/search using word forms. First of all I do not wanna to write all by my self. If I use StandardAnalyzer with QueryParser I can find the text like:
some testing text
by queries like "test~", "testing", but it is not works if I try to find it by query like "tested".
So please tell me how to make it right;)))
Thank you for any advice!!!
Make sure you use luke for testing queries etc:
http://www.getopt.org/luke/
It will rewrite and decomponse your query so you can debug the situation.