I want to search for a string in Sphinx and get all documents that contains that string
Example: search for "bot" and get the documents that contain "xbot", "robot", "botanic", etc
Basically I want my search to have same effects as running a
SELECT * FROM table WHERE column_name LIKE '%bot%'
How can I do that?
Note:
I tried to use min_infix_len but it seems that is only extends the search a little bit but not fully. So if I set conf-min-prefix-len = 2 it will match 'xbot' but not "botanic"
Try using wildcard in Extended Query Syntax and min_infix_len enabled
SELECT * FROM myindex WHERE MATCH("bot | bot* | *bot*")
Related
I'm trying to write a prometheus query in grafana that will select visits_total{route!~"/api/docs/*"}
What I'm trying to say is that it should select all the instances where the route doesn't match /api/docs/* (regex) but this isn't working. It's actually just selecting all the instances. I tried to force it to select others by doing this:
visits_total{route=~"/api/order/*"} but it doesn't return anything. I found these operators in the querying basics page of prometheus. What am I doing wrong here?
May be because you have / in the regex. Try with something like visits_total{route=~".*order.*"} and see if the result is generated or not.
Try this also,
visits_total{route!~"\/api\/docs\/\*"}
If you want to exclude all the things that has the word docs you can use below,
visits_total{route!~".*docs.*"}
The main problem with your original query is that /api/docs/* will only match things like /api/docs and /api/docs//////; i.e. the * in your query will match 0 or more / characters.
I think what you meant to use was /api/docs/.*.
Is there a way to use UPPER with a LIKE ANY()?
I have the following example:
SELECT
....
where skus.number like any ('{"%00130204%", "%00130202"}')
Unfortunately the skus I'm checking here can be of different cases, so I tried doing this:
SELECT
....
where UPPER(skus.number) like any UPPER('{"%00130204%", "%00130202"}'))
Which doesn't work, is there any way to get this working in the query itself?
No need to use upper. Use the case insensitive version of like, "ilike" instead.
SELECT
....
where skus.number ilike any ('{"%00130204%", "%00130202"}')
along with being totally with #Joe on his answer as better for you query (and skipping phylosophy behind idea to represent digits in uppercase), I decided to answer the topic of your post
Is there a way to use UPPER with a LIKE ANY()?
yes - here it is:
t=# select UPPER('110013020411') like any (UPPER('{"%00130204%", "%00130202"}')::text[]) comaprison;
comaprison
------------
t
(1 row)
after you upper text in array represented as text you need to cast it back inorder to use with ANY (array)
Not sure if what I want to do is possible
But here it goes
A sql select command like...
select origtxno from posinvtrans
will return a value like
1-5454 or 23-54545 etc.
What I am after is removing everything before and including "-" in a select
example 1-5454 will be 5454 and 23-54545 will be 54545
Any suggestions?
select substring(origtxno from position('-', origtxno) + 1)
from posinvtrans
how do i perform wildcard search a word in lucene that contain special character. for example i have a word like "91-95483534" if i search like "91*" it works and if i search like "91-95483534" also works fine. but my senario is that to search "91-9548*". if i perform like this "91-9548*". i got no output. am i missing anything. my actual code is given below:
MultiFieldQueryParser queryParser = new MultiFieldQueryParser(new string[] {"column1","column2"}, new StandardAnalyzer());
queryParser.SetAllowLeadingWildcard(true);
Query query = queryParser.Parse(QueryParser.Escape(strKeyWord) + "*");
As you used StandardAnalyzer, that indexed your word as 91 and 95483534 if you used INDEX_ANALYZED when you index....
if you want to search as 91-9548* , use INDEX_NOT_ANALYZED when you index that specified field which have "91-95483534" as terms
http://lucene.apache.org/core/old_versioned_docs/versions/3_0_3/api/core/org/apache/lucene/document/Field.Index.html
I did such search,
` Comment.search "aabbb "`
and I want to get the results which contain "ab" too.;
So I did that way:
` Comment.search "aabbb ab"`
but I found the results aabbb and ab are mixed , in fact, I want to make the results which match aabbb shows before ab, in other words, have a higher priority.
I know sphinx can add weight the fields of the table. for example add 10 to comments's name, 20 to comment's content. but is it possible to add weight to the query works?
Unfortunately this is not possible with sphinx yet but you can add similar behavior on a query by adding multiple times the keyword you want to weight.
For example:
"aabbb | aabbb | ab"
The aabbb is twice more important than ab
Sphinx has no ability to weight certain search phrases, I'm afraid - so what you're trying to do is not possible.
It's also worth noting that Sphinx uses AND logic by default - if you want results that match either aabbb OR ab, you'll probably want to use the :any match mode:
Comment.search "aabbb ab", :match_mode => :any