QueryMalformedException - sql

I am configuring a custom search for a Sharepoint application, and I am having trouble forming the FullTextSqlQuery query.
My code earns a QueryMalformedException (Your query is malformed. Please rephrase your query.) when I attempt to execute the query.
Here is my code:
search = new FullTextSqlQuery(site);
search.QueryText = string.Format("select Title, Path, Description, Rank, Size FROM SCOPE() WHERE \"scope\" = 'Documents' AND CONTAINS (\"{0}\")", EntreeScope.FormProperties["searchBox"]);
where the value of scope.FormProperties["searchBox"] is the query text and site is the current SPSite. Documents is a defined Search Scope on the default Search Service Application on the server.
Thanks in advance,
Brent

Try this out
search = new FullTextSqlQuery(site); search.QueryText = string.Format("select Title, Path, Description, Rank, Size FROM SCOPE() WHERE \"scope\" = 'Documents' AND CONTAINS ('\"{0}\"')", EntreeScope.FormProperties["searchBox"]);
Really just adding single quotes around your contains criteria
Check out CONTAINS Predicate in SharePoint Search SQL Syntax for more details because it depends on what you are trying to achieve.

Related

How to use regex URL to query a Google Spreadsheet

The following queries column A in a published Google Spreadsheet. The result is all rows with text comment in them.
var word = "comment";
var id = "unBCxSc8hR41dg6s6N3d17uccj8jnK5Xsn68C58Y76r9";
var url = "https://docs.google.com/spreadsheets/d/"+id+"/gviz/tq?tq=SELECT%20*%20where%20A%20contains%20%22"+word+"%22";
Please tell me what changes should I make to the URL in order to use regex.
For example, I need to find all rows with pattern co..en.* or .*ment in them.
~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~·~
EDIT
After Tanaike's help:
var word = "f.*t";
var columna = "A";
var id = "4tz810VLT4qv7Q9t94p24tz810VLT4qv7Q9t94p24tz8";
var url = "https://docs.google.com/spreadsheets/d/"+id+"/gviz/tq?tq=select%20"+columna+"%20where%20A%20matches%20%27"+word+"%27";
This will match fit, faint, font, fruit, feet, fat, etc.
~ finis ~
You want to retrieve the values using the regex of co..en.* or .*ment.
You want to achieve this using the query language of Google Visualization API.
If my understanding is correct, how about this answer? Please think of this as just on of several possible answers.
In this case, how about using matches? The modified query is as follows.
Modified query:
select * where A matches 'co..en.*|.*ment'
In this case, in order to use this query, please encode it with the URL encode. So when your endpoint is modified, please modify as follows.
From:
tq=SELECT%20*%20where%20A%20contains%20%22"+word+"%22"
To:
tq=select%20%2A%20where%20A%20matches%20%27co..en.%2A%7C.%2Ament%27
Reference:
Query Language Reference
If I misunderstood your question and this was not the result you want, I apologize.

How do you get Endeca to search on a particular target field rather than across all indexed fields?

We have an Endeca index configured across multiple fields of email content - subject and body. But we only want searches to be performed on the subject lines. Endeca is returning matches within the bodies too. How do you limit the search to the subject?
You can search a specific field or fields by specifying it (them) with the Ntk parameter.
Or if you wish to search a specific group of fields frequently you can set up an interface (also specified with the Ntk parameter), that includes that group of fields.
This is how you can do it using presentation API.
final ENEQuery query = new ENEQuery();
final DimValIdList dimValIdList = new DimValIdList("0");
query.setNavDescriptors(dimValIdList);
final ERecSearchList searches = new ERecSearchList();
final StringBuilder builder = new StringBuilder();
for(final String productId : productIds){
builder.append(productId);
builder.append(" ");
}
final ERecSearch eRecSearch = new ERecSearch("product.id", builder.toString().trim(), "mode matchany");
searches.add(eRecSearch);
query.setNavERecSearches(searches);
Please see this post for a complete example.
Use Search Interfaces in Developer Studio.
Refer - http://docs.oracle.com/cd/E28912_01/DeveloperStudio.612/pdf/DevStudioHelp.pdf#page=209

Endeca UrlENEQuery java API search

I'm currently trying to create an Endeca query using the Java API for a URLENEQuery. The current query is:
collection()/record[CONTACT_ID = "xxxxx" and SALES_OFFICE = "yyyy"]
I need it to be:
collection()/record[(CONTACT_ID = "xxxxx" or CONTACT_ID = "zzzzz") and
SALES_OFFICE = "yyyy"]
Currently this is being done with an ERecSearchList with CONTACT_ID and the string I'm trying to match in an ERecSearch object, but I'm having difficulty figuring out how to get the UrlENEQuery to generate the or in the correct fashion as I have above. Does anyone know how I can do this?
One of us is confused on multiple levels:
Let me try to explain why I am confused:
If Contact_ID and Sales_Office are different dimensions, where Contact_ID is a multi-or dimension, then you don't need to use EQL (the xpath like language) to do anything. Just select the appropriate dimension values and your navigation state will reflect the query you are trying to build with XPATH. IE CONTACT_IDs "ORed together" with SALES_OFFICE "ANDed".
If you do have to use EQL, then the only way to modify it (provided that you have to modify it from the returned results) is via string manipulation.
ERecSearchList gives you ability to use "Search Within" functionality which functions completely different from the EQL filtering, though you can achieve similar results by using tricks like searching only specified field (which would be separate from the generic search interface") I am still not sure what's the connection between ERecSearchList and the EQL expression above?
Having expressed my confusion, I think what you need to do is to use String manipulation to dynamically build the EQL expression and add it to the Query.
A code example of what you are doing would be extremely helpful as well.

SQL Select Like Keywords in Any Order

I am building a Search function for a shopping cart site, which queries a SQL Server database. When the user enters "Hula Hoops" in the search box, I want results for all records containing both "Hula" and "Hoop", in any order. Furthermore, I need to search multiple columns (i.e. ProductName, Description, ShortName, MaufacturerName, etc.)
All of these product names should be returned, when searching for "Hula hoop":
Hula hoop
Hoop Hula
The Hoopity of xxhula sticks
(Bonus points if these can be ordered by relevance!)
It sounds like you're really looking for full-text search, especially since you want to weight the words.
In order to use LIKE, you'll have to use multiple expressions (one per word, per column), which means dynamic SQL. I don't know which language you're using, so I can't provide an example, but you'll have to produce a statement that's like this:
For "Hula Hoops":
where (ProductName like '%hula%' or ProductName like '%hoops%')
and (Description like '%hula%' or Description like '%hoops%')
and (ShortName like '%hula%' or ShortName like '%hoops%')
etc.
Unfortunately, that's really the only way to do it. Using Full Text Search would allow you to reduce your criteria to one per column, but you'll still have to specify the columns explicitly.
Since you're using SQL Server, I'm going to hazard a guess that this is a C# question. You'd have to do something like this (assuming you're constructing the SqlCommand or DbCommand object yourself; if you're using an ORM, all bets are off and you probably wouldn't be asking this anyway):
SqlCommand command = new SqlCommand();
int paramCount = 0;
string searchTerms = "Hula Hoops";
string commandPrefix = #"select *
from Products";
StringBuilder whereBuilder = new StringBuilder();
foreach(string term in searchTerms.Split(' '))
{
if(whereBuilder.Length == 0)
{
whereBuilder.Append(" where ");
}
else
{
whereBuilder.Append(" and ");
}
paramCount++;
SqlParameter param = new SqlParameter(string.Format("param{0}",paramCount), "%" + term + "%");
command.Parameters.Add(param);
whereBuilder.AppendFormat("(ProductName like #param{0} or Description like #param{0} or ShortName like #param{0})",paramCount);
}
command.CommandText = commandPrefix + whereBuilder.ToString();
SQL Server Full Text Search should help you out. You will basically create indexes on the columns you want to search. in the where clause of your query you will use the CONTAINS operator and pass it your search input.
you can start HERE or HERE to learn more
You might want to check out SOLR too - if you're going to be doing this type of searching. Super cool.
http://lucene.apache.org/solr/

Dynamic querystring in JRXML [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I'm trying to build a report that would be smart enough to modify slightly its sql query based on an input parameter of some sort.
For example if that special modifying parameter value is "1", it adds a field in the select and adds a group by clause to the query.
I've looked into java expressions, but they don't seem to be supported in the queryString tag of the jrxml. Also tried to make a variable containing the java expression and use that variable in the queryString tag... That didn't work either!
Right now I'm thinking of maybe have a stored procedure with all that logic and simply have the jrxml calling that stored procedure with the modifying input parameter, but the project I'm working on doesn't seem to have a whole lot of stored proc, so I'd like to see if there are other solutions before I go down that path.
Thanks for your help.
Thank you guys for your help, much apprieciated. However I found another way to go about it, and posted it for information: here
JasperDesign actually lets you modify portions of your jrxml document. So say you have a package "reports" where you store your report built either by hand or by a tool like iReport. As long as your query is defined in the tag <queryString> the following will work allowing you to change the query on the fly:
try {
String fileName = getClass().getClassLoader().getResource("com/foo/myproject/reports/TestReport.jrxml").getFile();
File theFile = new File(fileName);
JasperDesign jasperDesign = JRXmlLoader.load(theFile);
//Build a new query
String theQuery = "SLECT * FROM myTable WHERE ...";
// update the data query
JRDesignQuery newQuery = new JRDesignQuery();
newQuery.setText(theQuery);
jasperDesign.setQuery(newQuery);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Connection conn = MyDatabaseClass.getConnection();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
JasperViewer.viewReport(jasperPrint);
} catch (Exception ex) {
String connectMsg = "Could not create the report " + ex.getMessage() + " " + ex.getLocalizedMessage();
System.out.println(connectMsg);
}
With something like this you can create a member variable of your class that holds the new query and build it with whatever user constrains desired. Then at view time just modify the design.
-Jeff
I've done it using stored procedures which are just fine for these kinds of stuff. Otherwise you may switch to Java. Just grab the data from the database and according to the user provided parameters filter it, group it and send as a collection of beans to the Jasper report which will do the rendering.
JasperDesign helped me to solve the problem of building dynamic query on Jrxml file.
To build the Dynamic SQL, I was using the Squiggle(Google Code) to build the SQL dynamically.
Thanks jeff