I have a custom FullTextSqlQuery used to retrieve some specific pages.
The query contains multiples FREETEXT predicates and gives unusable rankings, which is expected behavior according to MSDN, the query should contain only one FREETEXT
The basic query that gives expected results is
SELECT Title, ACLanguage, ACContent, ACCategory, ACKeywords, ACID
FROM scope()
WHERE (FREETEXT(Title,'text') OR FREETEXT(ACContent, 'text') OR FREETEXT(ACSubtitle, 'text'))
The documentation says this query can be rewritten to use a single predicate using a group alias, but it isn't clear about syntax. I tried multiple statements ending with :
SELECT Title, ACLanguage, ACContent, ACCategory, ACKeywords, ACID
FROM scope()
WHERE WITH(Title, ACSubtitle, ACContent) AS #SearchColumns FREETEXT(#SearchColumns,'text')
But all my attemps ended with a QueryMalformedException
How should this query be written ?
Specify multiple columns like this:
SELECT Title, ACLanguage, ACContent, ACCategory, ACKeywords, ACID
FROM scope()
WHERE (FREETEXT((Title,ACContent,ACSubtitle),'text'))
Or, shorthand for searching all full text indexed columns:
SELECT Title, ACLanguage, ACContent, ACCategory, ACKeywords, ACID
FROM scope()
WHERE (FREETEXT(*,'text'))
(source)
Related
I have a use case where given a user input I want to search across different fields. So I am able to do a query like
for v in myview
search analyzer(v.host_name == tokens(SOME_INPUT, 'text_en')[0] OR
v.ip_address == tokens(%input%, 'text_en')[0], "text_en")
return v
and it works.
But now some of the fields have different analyzer so I in the above query, I would like to use e.g. ngram for ip_address but then the above query will not work as the second argument to analyzer(....) is text_en.
Reading the docs at https://www.arangodb.com/docs/stable/aql/operations-search.html, it does not seem like I can have multiple SEARCH stanza in the same query.
What would be the way to do a query like that?
I want to search for a field that has the name "14009-00080300", and I want to get a hit when searching only on a part of that, for example "14009-000803".
Using this code I dont get any hits:
{
"search": "\"14009-000803\"*",
"count":true,
"top":10
}
Is there a way to use azure search like SQL uses its wildcard search? (select * from table where col like '%abc%' ?
You can get your desired result by performing a full query with Lucene syntax (as noted by Sumanth BM). The trick is to do a regex search. Modify your query params like so:
{
"queryType": "full",
"search": "/.*searchterm.*/",
"count":true,
"top":10
}
Replace 'searchterm' with what you are looking for and azure search should return all matches from your index searchable columns.
See Doc section: MS Docs on Lucene regular expression search
You can use generally recognized syntax for multiple () or single (?) character wildcard searches. Note the Lucene query parser supports the use of these symbols with a single term, and not a phrase.
For example to find documents containing the words with the prefix "note", such as "notebook" or "notepad", specify "note".
Note
You cannot use a * or ? symbol as the first character of a search.
No text analysis is performed on wildcard search queries. At query time, wildcard query terms are compared against analyzed terms in the search index and expanded.
SearchMode parameter considerations
The impact of searchMode on queries, as described in Simple query syntax in Azure Search, applies equally to the Lucene query syntax. Namely, searchMode in conjunction with NOT operators can result in query outcomes that might seem unusual if you aren't clear on the implications of how you set the parameter. If you retain the default, searchMode=any, and use a NOT operator, the operation is computed as an OR action, such that "New York" NOT "Seattle" returns all cities that are not Seattle.
https://learn.microsoft.com/en-us/rest/api/searchservice/simple-query-syntax-in-azure-search
Reference: https://learn.microsoft.com/en-us/rest/api/searchservice/lucene-query-syntax-in-azure-search#bkmk_wildcard
The "Exact Search" fields use their own custom analyzer, while the Search fields use a language specific custom analyzer (built on MicrosoftStemmingTokenizerLanguage.French, for example).
I can't seem to use $filter for the "Exact Search" field, because $filter considers the entire field, and doesn't use the custom analyzer of the field.
Azure Search docs indicate this about field scoped queries.
"You can specify a fieldname:searchterm construction to define a fielded query operation, where the field is a single word, and the search term is also a single word"
There is no clear way on how to do this in Azure. We know we can use the searchFields parameter in our Azure Search Rest API calls to target specific fields, but how do we search ALL fields for 1 term while specifically searching some fields for specific terms, basically doing an “AND” between them?
This is possible using the Lucene query syntax.
Construct your query like this, where "chair" is the term to search for in all fields, and field1 and field2 are fields where you want to search for specific terms:
chair AND field1:something AND field2:else
In terms of how you use this in the REST API, just embed it in your search parameter. If you're using GET it looks like this (imagine it URL-encoded):
search=chair AND field1:something AND field2:else
If you're using POST, it goes in the request body and looks like this:
{
"search": "chair AND field1:something AND field2:else",
... (other parameters)
}
I have many articles and each is assigned under different categories/subcategories.
What I'd like to do is at the end of individual article, I'll display a list of Related Articles based on the category(s) that the current article is placed. I've added a Repeater but don't really know what to put in Content Filter/Category Name to achieve this. Hope it's not so complex. Thanks for your input!
You can achieve this in Portal without touching the code if you need to. The following steps are how you can achieve it (though they are rough and ready!)
In your Article page type, create a new query. This queries job is going to be to link the existing Document to any others that share the exact same categories. Your query should look like this:
SELECT ##TOPN## ##COLUMNS##
FROM View_CMS_Tree_Joined rel
INNER JOIN CMS_DocumentCategory relcat ON relcat.DocumentID=rel.DocumentID
INNER JOIN CMS_DocumentCategory doccat ON relcat.CategoryID=doccat.CategoryID
WHERE ##WHERE##
AND rel.DocumentID doccat.DocumentID
ORDER BY ##ORDERBY##
Now, replace you Repeater with a Repeater with custom query. In the setting, choose your newly created query for the Query name field using the selector control.
Set the WHERE clause to be doccat.DocumentID={% CurrentDocument.DocumentID #%}
Pick the appropriate transformation and you should be good to go.
This method requires an exact category match, so Categories > Cars > Mazda will not match to Categories > Cars.
Hopefully this is of some use :)
This article may give you some idea on creating a filter, but I don't think this is exactly what you want. It does show you have to get the documents thru the API.
You could do a custom query, something like this
SELECT *
FROM dbo.View_CMS_Tree_Joined vctj
WHERE vctj.DocumentID IN
(
SELECT DocumentID
FROM CMS_DocumentCategory
WHERE CategoryID IN
(
SELECT CategoryID
FROM CMS_Category
WHERE dbo.CMS_Category.CategoryName = 'Name Here'
)
);
I am looking for a way to do wildcard search only on specific elements when executing a search:search. Specifically, I might have documents that look like the following:
<pdbe:person-envelope xmlns:pdbe="http://schemas.abbvienet.com/people-db/envelope">
<person xmlns="http://schemas.abbvienet.com/people-db/model">
<costcenter>
<code>0000601775</code>
<name>DISC-PLAT INFORM</name>
</costcenter>
<displayName>Tj Tang</displayName>
<upi>10025613</upi>
<firstName>
<preferred>TJ</preferred>
<given>Tze-John</given>
</firstName>
<lastName>
<preferred>Tang</preferred>
<given>Tang</given>
</lastName>
<title>Principal Research Scientist</title>
</person>
<pdbe:raw/>
</pdbe:person-envelope>
When searches happen, I want the search text to be automatically wildcarded, but only for certain elements like displayName, firstName, lastName, but NOT for upi or code. As I understand it, I would have certain wildcard related indexes enabled in the database, but then I would need to have a custom query parser that rewrite the query into multiple cts:element-query and cts:element-value-query statements for each element that I want to wildcard search on, OR'd with the originally parsed search query. Or I can create field constraints, and rewrite the query to use field contraints.
Is there another way to conditionally search using wildcard on some elements but not others, when the user is entering as simple search query?, i.e. partial first and last name, "TJ Tan", but no partial hits when I search "100256".
You are on the right track. Lets take an element (or maybe field) query on "TS Tan"
With cts:tokenize, you can break this up (read about cs:tokenize - it is not just a normal tokenizer).
Then I have "TS" and "Tan"
You can the do things like apply business rules on which word should be wild-carded and which not and build the appropriate cts query (probably individual word queries in an and statement - or a near query - tuning depends on your need).
Now with search phrase tokenized, you can also consider that you may find building your results relies not on a wildcard index, but on a an element word lexicon - where you do your term-expansion with word-matches and those terms are then sent to the query.
We sometimes take that further and combine the query building with xdmp:estimate and make the query less restrictive if we don't get enough results early on.
Where to put this logic?
You mention search:search, so in this case, I would suggest you package this into a custom constraint.