Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need to write a HTML file which will search a Keyword (might contain more than 1 word) in the contents/Documents of SP2010 site.

I am searching hardcoded word - Links in the below code. I don't know how to give the path of the ASMX file so that the search should be performed in the mentioned SharePoint site.

Kindly look into the code and suggest the possible solution.

Here is the code of HTML file -
HTML
<html>
    <head>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
        <script type="text/javascript" src="http://googlemapsharepoint.googlecode.com/files/jquery.SPServices-0.5.8.js"></script>
    </head>

    <body>
        <div>
            <script type="text/javascript">

                var queryText = "<querypacket xmlns="urn:Microsoft.Search.Query" revision="1000">"
                queryText += "<query>"
                queryText += "<context>"
                queryText += "<querytext language="en-US" type="STRING">"
                queryText += "Links"; 
                queryText += "</querytext>"
                queryText += "</context>"
                queryText += "</query>"
                queryText += "</querypacket>";

                $(document).ready(function() {

                    $('#SearchSPContents').click(function() {

                        alert("testing..." + queryText);
                        var title, url = ""; 

                           $().SPServices({ 
                               operation: "Query", 
                               queryXml: queryText, 
                               completefunc: function(xData, Status) {

                                    if (Status != "success") {
                                        displayNewsErrorMessage();
                                        return;
                                    }

                                    $(xData.responseXML).find("QueryResult").each(function() { 
                                        var queryResult = $(xData.responseXML).find("QueryResult").text();
                                        alert('queryResult : ' + queryResult);
                                       //let's see what the response looks like 
                                       $("#result").text($(this).text()); 
                                   }); 
                               } 
                           });
                    });
                });

            </script>

            <ul id="data1"></ul>
            <input type="button" id="SearchSPContents" value="SearchSPContents"/>
            <div id="response" />
        </div>
    </body>

</html>
Posted
Updated 8-Jan-12 23:09pm
v2

With 2010 you don't need to use webservices. You can use the Client Object Model to construct and execute a query. SharePoint 2010 Client Object Model, Part 1[^]

SharePoint web services are in the mapped folder vti_bin for each web application. http://msdn.microsoft.com/en-us/library/ee705814.aspx[^]
 
Share this answer
 
v2
Comments
Member 8551331 10-Jan-12 3:28am    
Hi Mark, Thanks for your response. In the meantime I worked on alternate approach. Now I am providing the path to the ASMX file and I believe it is hitting the mentioned Sharepoint Site. However the Response is still not Valid. Kindly suggest the fix.

Here is the code -

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
</head>

<body>
<div>
<script type="text/javascript">

// *** Customizable parameters ***
var quickSearchConfig = {
scope: "All Sites", // search scope to use
numberOfResults: 15, // number of results to show
};

$(document).ready(function () {

$('#GetList').click(function() {

alert('sds ' + $("#quickSearchTextBox").val());

var queryXML =
"<querypacket xmlns="urn:Microsoft.Search.Query" revision="1000"> \
<query domain="QDomain"> \
<supportedformats><Format>urn:Microsoft.Search.Response.Document.Document</Format> \
<context> \
<querytext language="en-US" type="STRING">SCOPE:\"" + quickSearchConfig.scope + "\"" + $("#quickSearchTextBox").val() + " \
\
<sortbyproperties><sortbyproperty name="Rank" direction="Descending" order="1"> \
<range><startat>1<count>" + quickSearchConfig.numberOfResults + " \
<enablestemming>false \
<TrimDuplicates>true</TrimDuplicates> \
<ignoreallnoisequery>true \
<implicitandbehavior>true \
<includerelevanceresults>true \
<includespecialtermresults>true \
<includehighconfidenceresults>true \
";

var soapEnv =
"<soap:envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:body> \
<query xmlns="urn:Microsoft.Search"> \
<queryxml>" + escapeHTML(queryXML) + " \
\
\
";

// Call web service
$.ajax({
url: "http://path/to/WSDL/file.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""
});

});
});

function escapeHTML (str) {
return str.replace(/&/g,'&').replace(//g,'>');
}


function processResult(xData, status) {
alert(xData);
//alert('$(this) : ' + $(this));
//alert('xData.responseXML : ' + xData.responseXML);

//alert('$(this).text() : ' + $(this).text());
alert('In processResult ' + xData.responseXML.xml);

//let's see what the response looks like
//$("#response").text($(this).text());
//$('#response').text(xData.responseXML.xml);
}

</script>

<ul id="data1"></ul>
<input style="width: 100px" id="quickSearchTextBox" class="ms-sbplain" title="Enter search words"
style="width: 170px" alt="Enter search words" maxlength="200" value="" />
<input type="button" id="GetList" value="GetList"/>

<div id="response" />

</div>
</body>

</html>
[no name] 10-Jan-12 21:36pm    
use the client object model. It is cleaner, easier to use and more efficient. Web services were carried over to 2010 for legacy support and all new applications use the COM
XML
I solved this by giving the older version of jquery.min.js
Here is the working code. You need to provide the path to the search.asmx file in your SharePoint Site/Repository.


<html>
 <head>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
 </head>

 <body>
  <div>
   <script type="text/javascript">

    // *** Customizable parameters ***
    var quickSearchConfig = {
     scope: "All Sites",     // search scope to use
     numberOfResults: 15    // number of results to show
    };

    $(document).ready(function () {

     $('#GetList').click(function() {

     //alert('sds ' + $("#quickSearchTextBox").val());

      var queryXML =
       "<QueryPacket xmlns='urn:Microsoft.Search.Query' Revision='1000'> \
       <Query domain='QDomain'> \
        <SupportedFormats><Format>urn:Microsoft.Search.Response.Document.Document</Format></SupportedFormats> \
        <Context> \
         <QueryText language='en-US' type='STRING' >SCOPE:\"" + quickSearchConfig.scope + "\"" + $("#quickSearchTextBox").val() + "</QueryText> \
        </Context> \
       <SortByProperties><SortByProperty name='Rank' direction='Descending' order='1'/></SortByProperties> \
        <Range><StartAt>1</StartAt><Count>" + quickSearchConfig.numberOfResults + "</Count></Range> \
        <EnableStemming>false</EnableStemming> \
        <TrimDuplicates>true</TrimDuplicates> \
        <IgnoreAllNoiseQuery>true</IgnoreAllNoiseQuery> \
        <ImplicitAndBehavior>true</ImplicitAndBehavior> \
        <IncludeRelevanceResults>true</IncludeRelevanceResults> \
        <IncludeSpecialTermResults>true</IncludeSpecialTermResults> \
        <IncludeHighConfidenceResults>true</IncludeHighConfidenceResults> \
       </Query></QueryPacket>";

      var soapEnv =
       "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
         <soap:Body> \
        <Query xmlns='urn:Microsoft.Search'> \
          <queryXml>" + escapeHTML(queryXML) + "</queryXml> \
        </Query> \
         </soap:Body> \
       </soap:Envelope>";

      // Call web service
      $.ajax({
       url: "http://<SHAREPOINT-SITE>/_vti_bin/search.asmx",
       type: "POST",
       dataType: "xml",
       data: soapEnv,
       complete: processResult,
       contentType: "text/xml; charset=\"utf-8\""
      });

     });
    });

       function escapeHTML (str) {
       return str.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
    }


    function processResult(xData, status) {
     //alert(xData);
     //alert('xData.responseXML : ' + xData.responseXML);
     //alert('In processResult ' + xData.responseXML.xml);

     //alert('$(this) : ' + $(this));
     //alert('$(this).text() : ' + $(this).text());

     //let's see what the response looks like
     //$("#response").text($(this).text());
     $('#response').text(xData.responseXML.xml);
    }

   </script>

   <ul id="data1"></ul>
   <input style="width: 100px" id="quickSearchTextBox" class="ms-sbplain" title="Enter search words"
        style="width: 170px" alt="Enter search words" maxlength="200" value="" />
   <input type="button" id="GetList" value="GetList"/>

   <div id="response" />

  </div>
 </body>

</html>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900