I am trying to build the lucene fulltext search with the wildcard expression to represent "Contains" /*.<Keyword>/*, but in the Buildparameter model which is provided by the Azure Search library does not have the search properties.
I am using
Documents.Search<T>(searchTerm, searchParam);
//where SearchTerm is the <typed key search> for ex "Nurs" and the result
//should be where all or any text contains "Nurs"
The Azure.Search.Models SearchParameter which i am using to build is where i Extended to create the new class to contain the Search field.
return new ExtentedSearchParameter
{
IncludeTotalResultCount = true,
SearchFields = new List<string>() {"FilterableTitle", "FilterableAlternativeTitle"},
Skip = (properties.Page - 1) * properties.Count,
Top = properties.Count,
Search=properties.SearchQuery,
QueryType = QueryType.Full ,
Select=new List<string>(){"FilterableTitle", "FilterableAlternativeTitle"},
OrderBy = properties.OrderByFields,
};
and in my application I am building the query like
if (string.IsNullOrWhiteSpace(returnProperties.FilterBy))
{
returnProperties.SearchQuery =$"FilterableTitle: /.*'{cleanSearchTerm.TrimStart('\"').TrimEnd('\"')}.*/' and FilterableAlternativeTitle:/.*'{cleanSearchTerm.TrimStart('\"').TrimEnd('\"')}.*/'";
}
When I am passing the searchparameter and the search term its not returning the result and its throwing an exception.
Instead of extending the SearchParameters class, you can pass your Lucene query as the searchText parameter to the Search method:
Documents.Search<T>(properties.SearchQuery, searchParam);
Related
In v10 of Azure Search SDK, I was able to specify exactly which fields to search in an index by taking advantage of SearchParameters class. In v11, I see there is SearchOptions, but the SearchFields parameter is get only. In v10, SearchFields has a setter.
How do I choose which fields to search on in v11?
You can call .Add() on the SearchFields property:
var options = new SearchOptions();
options.SearchFields.Add("field1");
options.SearchFields.Add("field2");
Or you can use C#'s list initializer syntax:
var options = new SearchOptions() { SearchFields = { "field1", "field2" } };
Example adapted from this GitHub issue.
We have a requirement where users are to be allowed to search a list called "Reports" from the front-end, and advanced search, such as author:"John Smith" or filetype:docx, is to be supported.
We decided that this can be achieved using Sharepoint Server Search API (using the Keyword Query Language). Also, since it is possible that all users don't have access to all items in the list, we decided to go with the approach to use a web method with elevated privileges to query the list.
This is my attempt so far...
public string GetSearchResults(string listname, string searchQuery)
{
SPUser superUser = SPContext.Current.Web.AllUsers[#"SHAREPOINT\SYSTEM"];
using (SPSite site = new SPSite(SPContext.Current.Web.Url, superUser.UserToken))
{
KeywordQuery keywordQuery = new KeywordQuery(site);
keywordQuery.QueryText = searchQuery;
//where should listname be specified?
SearchExecutor searchExecutor = new SearchExecutor();
ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery);
var resultTables = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults);
ResultTable resultTable = resultTables.FirstOrDefault();
DataTable dataTable = resultTable.Table;
}
//how to parse result to filter only items in given list?
}
...but what I don't understand is how to restrict search to only a given list or how to parse the search result to retrieve items of the list matching the search query.
I'm new to Sharepoint search, so any pointers would help.
This is possible either to give list path or list guid in query text
keywordQuery.QueryText = "Path:/Sales/Lists/Prospects/ (contentclass:STS_ListItem OR IsDocument:True) -ContentClass=urn:content-class:SPSPeople ";
I have a property in my index (using the Advanced Database Crawler) for an archive date.
I want to find all items where the date is null or in the future....Date range search will accomplish the second part, but what about the first?
You can't do a null search against Lucene. What I've done in the past is to test for emtpy fields and insert the word "EMPTY" in the index. Then when querying the index you need to add a test that checks for the presence (or absence) of that term. It feels kind of dirty doing it that way but that is the only solution I've been able to find or come up with in the 3 years I've been working with Sitecore and Lucene.
In the DateFieldCrawler class, we modified the following code:
public override string GetValue()
{
if (String.IsNullOrEmpty(_field.Value))
{
return DateTools.DateToString(DateTime.MinValue, DateTools.Resolution.DAY);
}
if (FieldTypeManager.GetField(_field) is DateField)
{
var dateField = new DateField(_field);
if(dateField.DateTime > DateTime.MinValue)
{
return DateTools.DateToString(dateField.DateTime, DateTools.Resolution.DAY);
}
}
return String.Empty;
}
By storing this value, we were able to perform the following queries to include null value dates:
DateRangeSearchParam.DateRange toFirstDate =
new DateRangeSearchParam.DateRange(EVENT_FIRST_DATE,
DateTime.MinValue, toDate.Value);
toFirstDate.InclusiveEnd = false;
eventDates.Add(toFirstDate);
I am trying to develop a customized SharePoint 2010 web part for FAST search. I am using Microsoft.Office.Server.Search.Query.KeywordQuery something like this:
var FASTquery = new KeywordQuery(proxy)
{
ResultsProvider = SearchProvider.FASTSearch,
QueryText = queryText,
ResultTypes = ResultType.RelevantResults | ResultType.RefinementResults
};
FASTquery.SelectProperties.AddRange(
new string[] { "Title", /* ..., */ "HitHighlightedSummary" });
ResultTableCollection searchResults = FASTquery.Execute();
I go on to bind searchResults[ResultType.RelevantResults] to a Repeater control. I'm trying to get the "hit highlighted summary" to appear by calling FASTquery.HighlightStringValue(). The value I'm passing is the HitHighlightedSummary from searchResults. An example of what this looks like for a result when searching for "ear" is:
<ddd/>FALSE ); GetDlgItem(IDC_<c0>EAR</c0>_PAIN_STATIC)->EnableWindow<ddd/>FALSE ); GetDlgIte(IDC_<c0>EAR</c0>_PAIN_ABSENT_RADIO<ddd/>FALSE ); GetDlgItem(IDC_<c0>EAR</c0>_PAIN_MILD_RADIO<ddd/>
However, when called with a string like this, FASTquery.HighlightStringValue() is throwing a System.ServiceModel.FaultException with the message "Value does not fall within the expected range."
What is the correct way to convert this excerpt to HTML, or should I be calling HighlightStringValue() with some other value? The documentation is not particularly helpful.
I typically perform a manual conversion of the hit highlighted summary markup to HTML. You'll find a combination of two markers in the summary:
<c0> </c0> (Highlight)
<ddd/> (Ellipsis)
A manual transformation of the markup could be as simple as the following string replacement:
string hitHighilghtedSummary;
// ...
hitHighlightedSummary = hitHighlightedSummary.Replace("c0", "strong").Replace("<ddd/>", "…");
I am having trouble with a MOSS FulltextSqlQuery when attempting to filter People results on the Skills Managed Property using the CONTAINS predicate. Let me demonstrate:
A query with no filters returns the expected result:
SELECT AccountName, Skills
from scope()
where freetext(defaultproperties,'+Bob')
And ("scope" = 'People')
Result
Total Rows: 1
ACCOUNTNAME: MYDOMAIN\Bob
SKILLS: Numchucks | ASP.Net | Application Architecture
But when I append a CONTAINS predicate, I no longer get the expected result:
SELECT AccountName, Skills
from scope()
where freetext(defaultproperties,'+Bob')
And ("scope" = 'People')
And (CONTAINS(Skills, 'Numchucks'))
Result
Total Rows: 0
I do realize I can accomplish this using the SOME ARRAY predicate, but I would like to know why this is not working with the CONTAINS predicate for the Skills property. I have been successful using the CONTAINS predicate with a custom crawled property that is indicated as 'Multi-valued'. The Skills property (though it seems to be multi-valued) is not indicated as such on the Crawled Properties page in the SSP admin site:
http:///ssp/admin/_layouts/schema.aspx?ConsoleView=crawledPropertiesView&category=People
Anyone have any ideas?
So with the help of Mark Cameron (Microsoft SharePoint Developer Support), I figured out that certain managed properties have to be enabled for full text search using the ManagedProperty object model API by setting the FullTextQueriable property to true. Below is the method that solved this issue for me. It could be included in a Console app or as a Farm or Web Application scoped Feature Receiver.
using Microsoft.Office.Server;
using Microsoft.Office.Server.Search.Administration;
private void EnsureFullTextQueriableManagedProperties(ServerContext serverContext)
{
var schema = new Schema(SearchContext.GetContext(serverContext));
var managedProperties = new[] { "SKILLS", "INTERESTS" };
foreach (ManagedProperty managedProperty in schema.AllManagedProperties)
{
if (!managedProperties.Contains(managedProperty.Name.ToUpper()))
continue;
if (managedProperty.FullTextQueriable)
continue;
try
{
managedProperty.FullTextQueriable = true;
managedProperty.Update();
Log.Info(m => m("Successfully set managed property {0} to be FullTextQueriable", managedProperty.Name));
}
catch (Exception e)
{
Log.Error(m => m("Error updating managed property {0}", managedProperty.Name), e);
}
}
}
SELECT AccountName, Skills
from scope()
where freetext(defaultproperties,'+Bob')
And ("scope" = 'People')
And (CONTAINS(Skills, 'Numchucks*'))
use the * in the end.
You also have a few more options to try:
The following list identifies
additional query elements that are
supported only with SQL search syntax
using the FullTextSqlQuery class:
FREETEXT()
CONTAINS()
LIKE
Source