So I've been using Sphinx with a rails project lately, I want to provide a list of 'would be' exact matches that would match 100% with a give term. For example something like:
+==================+==========================================================+
| ingredient | exact matches |
+==================+==========================================================+
| cheese, cream | 'cream cheese','philadephia cream cheese','cream chese',|
| | 'creamed cheese' |
+------------------+----------------------------------------------------------+
| Cheese, gruyere | 'gruyere','gruyer cheese','gruyeres cheese' |
| | 'gruyere chese' |
+------------------+----------------------------------------------------------+
| Cheese, blue | 'blue cheese','blu cheese' |
+------------------+----------------------------------------------------------+
So basically the functionality I'm looking for would be that Sphinx would try to do its typical matching on all the records, but if the search term matches exactly with one of the strings in an array in that record that result would have a much higher weight. (like 100x, so it would then be the best match)
Is this possible? It seems like other people would have had this problem before... no?
Update
I suppose the best answer might be to just index the exact matches column and provide a really high weight to the terms.
I'm not sure how I can break up the "array" and see if the search term matches exactly though...
Your should try to play with sphinx search modes. Look at match phrase and match extended2.
Related
I am currently working with Postgresql and I am facing a problem.
I have two tables "question" and "question_detail" in which there are codes. In "question_detail" are the codes including subcode so e.g. TB01Q07, TB01Q07a, TB01Q08_SQ002. Now I wanted to use the command LIKE to see if the table "question" also contains these records. But in "question.code" there are only codes without the following underscore. This is a table that was given to me, I find this somehow very stupid.
The problem is that when I search with LIKE the value TB01Q07a is listed twice. This is also understandable to me, since searching for TB01Q07% also returns the value TB01Q07a.
Does anyone know of a way to search only for TB01Q07a without it resulting in TB01Q07% as TB01Q07a?
Command
SELECT qd.code, qd.label, q.type
FROM public.question q,
public.question_detail qd
where CASE
WHEN qd.code = q.code THEN qd.code = q.code
ELSE qd.code like CONCAT(q.code,'%')
END;
question
| code | type |
| ---------|-------- |
| TB01Q07 | comment |
| TB01Q07a | comment |
| TB01Q08 | option |
**question_detail**
```none
| code | label |
| -------------- | ------|
| TB01Q07 | AB01 |
| TB01Q07a | AB02 |
| TB01Q08_SQL002 | AB03 |
I ran the SQL and wanted the TB01Q07a value to appear only once and not be listed twice.
I think I have found a solution with distinct on.
SELECT distinct on (qd.code) q.id_question,qd.code, q.question, q.question_type
FROM public.question q, public.question_detail qd
where qd.code like CONCAT(q.code,'%');
like('TB01Q07%') matches both TB01Q07 and TB01Q07a, so you get two rows for TB01Q07 and one row for TB01Q07a.
You need to be more precise and include the underscore. Also make sure it's escaped, _ means any one character in a like.
There is no need for a case, use or. Avoid using multiple from statements, use an explicit join with an explicit on. This is clearer and gives you more control over the join.
select qd.*, q.*
from public.question q
join public.question_detail qd
on qd.code = q.code OR qd.code like q.code || '\_%'
Demonstration.
Note: this problem doesn't exist if you use foreign keys. Assign unique IDs to question and reference them in question_detail. This is faster, shields you from changes to the question code, and ensures the referred to question exists.
Consider the following dataset:
<uses-configuration
android:reqFiveWayNav=["true" | "false"]
android:reqHardKeyboard=["true" | "false"]
android:reqKeyboardType=["undefined" | "nokeys" | "qwerty" | "twelvekey"]
android:reqNavigation=["undefined" | "nonav" | "dpad" | "trackball" | "wheel"]
android:reqTouchScreen=["undefined" | "notouch" | "stylus" | "finger"] />
I am trying to select all the values after android:
In order to do this, i am using (a\w+:)(\w+) which does exactly what i want. I know that I can use the search and replace and use$2 to select the second group, but I dont want to replace anythin. I want to select anything the second group matches with alt+enter key press.
Is this possible?
What you really need is a lookaround. I don't believe that vscode supports lookbehinds (see issues: lookbehind support coming). But it does support lookaheads so :
(\w+)(?=\=\[.*\])
should work for you as long as your desired values are followed by "[.*]" and nothing undesired has that pattern. The lookahead part will not be selected by vscode. And then Alt-Enter selects all the matches.
If lookbehind was supported, maybe soon, this would work:
\b(?<=a\w+:)(\w+)\b
Just a note that indeed lookbehinds were implemented in vscode since the question and answer so the lookbehind solution \b(?<=a\w+:)(\w+)\b does work now.
I am using sphinx with soundex morphology. I want to use wordworms.
Which form of word do I need to use like a result?
call keywords ('azori', 'test', 1);
+------+-----------+------------+------+------+
| qpos | tokenized | normalized | docs | hits |
+------+-----------+------------+------+------+
| 1 | azori | a260 | 1550 | 1551 |
+------+-----------+------------+------+------+
1 row in set (0.00 sec)
In wordforms I need to use
azouri > azori
or
azouri > a260
Is is probably the critical bit from the documentation:
wordforms .. It can also be used to implement stemming exceptions, because stemming is not applied to words found in the forms list.
http://sphinxsearch.com/docs/current.html#conf-wordforms
... ie stemming (actually morphology, and hence soundex) algorithm is not run on words/tokens transformed by wordforms. Hence yes you do have to manually 'soundex' the destination keyword.
What's the best way to translate the database content of a zend application ?
I am thinking to add field to database tables
Or create others tables
What I do is to have two tables and a view.
Let's say we have "nouns". So, I create a table NOUN_R with only "IdLanguage" (and whatever needed), another table NOUN_TR (translation), with, "IdLanguage" , a Locale (EN, DE, ...), description and text.
So far:
NOUN_R
NOUN | IDlanguage
Yellow | 1
Red | 2
NOUN_TR
NOUN | IDlanguage | Language
Yellow | 1 | EN
Giallo | 1 | IT
Red | 2 | EN
Rosso | 2 | IT
Finally, you get a view which filters on Locale!
That's the way I'm using right now, not the "best solution" :)
I have more than 3 views. My database looks like this:
Category:
CatID | CatTitle
----------------
1 | XYZ
2 | Sample
Content:
ItemID | ItemCatID | ItemText | ItemText2 | ItemText3 | ItemText4
-----------------------------------------------------------------
1 | 1 | Test | Bla | Sample | MoreContent
2 | 1 | Test2 | BlaBla | Sample2 | Other Content
3 | 2 | Test3 | BlaBla2 | Sample3 | Other Content2
I want a view where first page category, second page list (ItemText), third page detail.
I'm not sure how to go about accomplishing that. If I use JOIN should I define "sqlite3_stmt *compiledStatement" in triple?
I think it can be done with 'For', "get parent,child" (like a cursor in java)?
Any advice welcome.
I'm not sure what you want.
Can you be more specific?
I can give you two tips though, first SQLite does not support stored procedures and has a very limited support for PL/SQL:http://www.sqlite.org/whentouse.html
if you REALLY MUST use it I suggest looking at this, I never tried it but it may work:
http://chriswolf.heroku.com/articles/2011/01/26/adding-stored-procedures-to-sqlite
Second, you usually wanna use a Wrapper around SQLite c functions so you worry about the SQL itself more and less about the c functions, examples:
Best Cocoa/Objective-C Wrapper Library for SQLite on iPhone
Hope this helps