Django filter custom look up - django

How can I add custom filtering to Django search?
currently lookup_expr='icontains' match the words that contains string.
Example:
I want to search the work "elephant". if i type ele, phant, then icontains works. But if i type elepant (missed h) then icontains wont return anything.
So I want to build the search text that matches similar word.
How can I do that in django?

This is called "full text search". If you are using postgres database then django has some native support for it. Otherwise, there is a huge branch of software devoted just to full text search out there, can start your journey here.

Related

How to generate Django template as MS word?

Is there a way to build a Django template or make it like Microsoft word by making the Django template have tools and the ability to write word documents from a website instead?
if we supposed that there is a domain name called: example.com
so, when I open that website for example.com/word-doc/ it will open a blank page and some tools from Microsoft Word to write in.
Is there any package or API to do so?
You are probably looking for a kind of "wysiwyg" editor for client side (this part has nothing do with Django). The closest thing I could found is this one, however it comes with a price tag.
In Django-side you'll (probably) simply store the data given by editor (client). The editor will then be able to parse it for update/read purposes.

Django using Postgres Full Text Search not recognizing certain words when setting config='english'

So I'm running into a very weird issue. I'm using Django's SearchQuery app in Django, using Django 3.2.1 and the most up to date PostgreSQL. The issue emerges when I use a search query with websearch and config set to english.
Here is the initial code for the instantiation of the search_query with config='english'
search_query = SearchQuery(query_string, search_type='websearch', config='english')
And this is the code for when I search for it:
agenda_items = AgendaItem.objects.annotate(search=SearchVector('name', 'description', 'note'),search_rank=SearchRank('search', search_query)).filter(search=search_query).order_by('-search_rank').distinct()
This works for most words, but I have found some weird outliers. For instance, it works when I search "flamingo" and it correctly matches it.
However, when I search for the word "cupcake" it displays nothing, despite the word actually being present in many records in the correct spots.
However, if I remove config='english' from the SearchQuery it works. But without that, I lose the English language support to stem words.
Does anyone have any ideas?

Solr search suggestion and results on wrong spelling

I am using solr 4.8.1 with django haystack and indexing across multiple fields - I am seeing a problem with some search queries that are spelt wrong, they are coming up with matches and also being put forward as a spelling suggestion.
Example: I have indexed documents that contain the word 'Berkeley' if I use the Solr admin UI and search for 'berkele' it comes up with the spelling suggestion 'berkelei' and then if i query 'berkelei' it will return 429 results (the same amount if I query 'berkeley')
I am using the example solrconfig.xml that came with solr and just generating the schema.xml using django haystack - has anyone got an idea why this would happen?
Basically I would like it to give the correct spelling suggestion when I query something like 'berkele' rather than another misspelt word
I managed to resolve this issue by removing from the schema.xml file generated by django-haystack.

Yahoo Pipes and Website Name

How do I fetch Page Name with Yahoo Pipes?
I'm making a news / blog aggregator, and need to know the name of the site where the info is coming from (bbc, cnn, fox, etc).
Do I need to do this with REGEX?
Anyone that can help?
You can fetch the page using the XPath Fetch Page or Fetch Feed modules in the Sources menu. Maybe with others too.
After that you can extract the page name itself using the various operators, possibly Regex, or others, depending on the source page you are using and the output you want to get.
In general your question is too broad and difficult to answer. To get you started, I created an example pipe that extracts the title of your question from this post, which is basically the "page name" of the current page.
http://pipes.yahoo.com/pipes/pipe.info?_id=668acf3f807c30d7b75f12459edd3252
I used the XPath Fetch Page with parameters:
URL = this page
Extract using XPath = //div[#id="question-header"]
I got that div path by inspecting the source code of this page, where I saw that div#question-header is the container of a question. I could have selected a deeper inner container or a higher level container. It all depends on the amount of other information you need. The more information you want to you from the page, the higher level container you select.
Next, I used the Create RSS operator to create a proper RSS feed, with parameters:
Title = h1.a
Link = h1.a.href
I chose these elements because in the container I extracted with xpath, the page name is inside h1 a. In Yahoo Pipes you use a dot as the path separator.
I found this sample pipe http://pipes.yahoo.com/pipes/pipe.info?_id=69b5dce1c59501a0c64a660c1cfdb856. The page title included the name of the site too. I am not sure if this what you are looking for.

Sitecore language search with Lucene.NET

I am using Alex Shyba's Advanced Database Crawler to index data from Sitecore and Lucene.NET queries to make search queries. I have it working solidly for the most part but having issues with the _language field when I try to do a term match for example en-US, zh-CN and de-DE.
It returns all results for the 'en' culture. But for example in the zh-CN culture it's returning about 99% of the results and leaving out 2-3 articles from each set. The en and zh-CN are different versions of the same item. I can see both information about the item in both cultures in the index via Luke.
I am using TermQuery on the language field to return data. I tried using PhraseQuery and WildCardQuery but everytime I got the same results.
I tried escaping the hyphen since Standard Analyzer doesn't like hypens with a back slash but that didn't work either.
At this point I am out of ideas. How can I have my queries return all the matching documents?
Thanks
The ADC has its own query objects to define search parameters. Simply use the Language property on the SearchParam object to search by a language.