Solved

How can I properly query SystemIndex when there are spaces?

Posted on 2014-10-03
5
160 Views
Last Modified: 2015-07-22
Hi!

I have a CLR function that I reference from SQL to carry out full-text searches. The problem I'm having is that the path where the documents reside contains a space i.e. "C:\My Documents\Information". When I place the call I receive no hits. Yet, if I carry out the sample call with a path that contains no spaces i.e. "C:\MyDocuments\Information" I receive a slew of responses.

My query to SystemIndex is formatted like so:

"SELECT System.FileName, System.ItemPathDisplay, System.DateModified FROM SystemIndex WHERE SCOPE = '" + Scope + "' AND CONTAINS('" + Contains + "')"

Open in new window


Does anybody know what I can do to get around this issue. All the examples I find online refer to a path that have no spaces, but client setups vary across the board and we can't enforce that as a rule.

Please help.
0
Comment
Question by:PlawCoder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40359606
AND CONTAINS('" + Contains.Replace(" ", "") + "')"
0
 

Author Comment

by:PlawCoder
ID: 40359613
The issue here is the SCOPE portion of the query. The path is the one that contains spaces.
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40359625
The solution is to replace space with an empty string . . . you can do that on the scope instead.
0
 

Author Comment

by:PlawCoder
ID: 40359641
Thanks Kyle.

But I can't effectively replace "C:\My Documents\Information" with "C:\MyDocuments\Information". That would yield an entirely different path, which doesn't even exist in my directory.

Perhaps I'm not understanding your statement.
0
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 40359662
Try the following:
string.Format("SELECT System.FileName, System.ItemPathDisplay, System.ItemType, System.Size, System.ItemDate, System.DateModified FROM " +
" myserver.systemindex WHERE SCOPE='{1}' AND" + 
" System.FileName LIKE " +  " '%{0}%'"
, searchString, searchLocation);

Open in new window

0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question