I have used the following code:
function searchSphinx2($tofind,$jobtype_id,$payper_id,$onetimeBounds)
{
$this->load->library('session');
$this->load->library('sphinxclient');
global $result;
global $functionresult;
$functionresult=array();
$this->sphinxclient->setServer('localhost', 3312);
$this->sphinxclient->SetMatchMode( SPH_MATCH_ANY );
$this->sphinxclient->SetIndexWeights( array("jobs_index_main"=>10, "jobs_index_delta"=>10,"jobs_index_prefix_main"=>1,"jobs_index_prefix_delta"=>1,"jobs_index_infix_main"=>1,"jobs_index_infix_delta"=>1) );
$this->sphinxclient->ResetFilters();
$this->sphinxclient->SetFilter('jobtype_id',$jobtype_id,TRUE);
$this->sphinxclient->SetFilter('payper_id',$payper_id,TRUE);
$this->sphinxclient->SetFilterFloatRange('payamount', $ontimeBounds[0], $ontimeBounds[1], FALSE);
$this->sphinxclient->AddQuery("$tofind", "jobs_index_main;jobs_index_delta");
$this->sphinxclient->AddQuery("*$tofind*", "jobs_index_main_prefix;jobs_index_delta_prefix");
$this->sphinxclient->AddQuery("*$tofind*", "jobs_index_main_infix;jobs_index_delta_infix");
$result = $this->sphinxclient->RunQueries();
In my data base there is a job with title "Intern" However, if I search for "inter" I do not get any results.
The indices in my confi file are set up as follows:
index jobs_index_prefix_main
{
source = jobs_main
path = /var/newsphinx/index/main_prefix
morphology = stem_en
min_stemming_len = 4
min_word_len = 3
min_prefix_len = 3
prefix_fields = title, contactname
enable_star =1
}
Can anyone tell me why I am not getting partial word results?
I've never found Sphinx to return partial matches without using stars. I agree that it's not particularly intuitive (surely if the prefixes are being indexed, there's a match?), but if you want to ensure you always get results, add a star to the end of each word.
Related
I have this line of code
query = query.Filter(i =>
(
!i.MatchTypeHierarchy(typeof(InfoPage))
| (((InfoPage)i).SearchSubsection().Exists()
& ((InfoPage)i).GetSearchSubSection().Contains(SOMETHING))
)
); // I want to check if it contains
I want to check if there is anything like a string contains a substring in FIND query.
Thanks for help in advance. :)
First things first, you are casting to InfoPage which indicates that you shouldn't be using Unified search, instead use the typed search feature.
Second, contains would typically be referred to as wildcard search.
I wrote a typed search wildcard method a while ago, see https://www.herlitz.io/2016/09/19/episerver-find-wildcard-searching/
public static class SearchExtensions
{
public static IQueriedSearch<T> WildCardSearch<T>(this ITypeSearch<T> search, string query)
{
return search.For<T>(query, q => q.Query = string.Concat("*", query, "*"));
}
}
Usage example
var result = SearchClient.Instance.Search<InfoPage>()
.WildCardSearch(query)
.OrderByDescending(x => x.Name)
.FilterForVisitor()
.GetContentResult();
We are interested in the statistics of the different pages combined from the Google Analytics core reporting API. The only way I found to query statistics multiple pages at the same is by creating a filter like so:
ga:pagePath==page?id=a,ga:pagePath==page?id=b,ga:pagePath==page?id=c
And this get escaped inside the filter parameter of the GET query.
However when the GET query gets over 2000 characters I get the following response:
414. That’s an error.
The requested URL /analytics/v3/data/ga... is too large to process. That’s all we know.
Note that just like in the example call the only part that is different per page is a GET parameter in the pagePath, but we have to OR a new filter specifying both the metric (pagePath) as well as the part of the path that is always identical.
Is there any way to specify a large number of different pages to query without hitting this limit in the GET query (I can't find any documentation for doing POST requests)? Or are there alternatives to creating batches of a max of X different pages per query and adding them up on my end?
Instead of using ga:pagePath as part of a filter you should use it as a dimension. You can get up to 10,000 rows per query this way and paginate to get all results. Then parse the results client side to get what you need. Additionally use a filter to scope the results down if possible based on your site structure or page names.
I am sharing a sample code where you can fetch more then 10,000 record data via help of Items PerPage
private void GetDataofPpcInfo(DateTime dtStartDate, DateTime dtEndDate, AnalyticsService gas, List<PpcReportData> lstPpcReportData, string strProfileID)
{
int intStartIndex = 1;
int intIndexCnt = 0;
int intMaxRecords = 10000;
var metrics = "ga:impressions,ga:adClicks,ga:adCost,ga:goalCompletionsAll,ga:CPC,ga:visits";
var r = gas.Data.Ga.Get("ga:" + strProfileID, dtStartDate.ToString("yyyy-MM-dd"), dtEndDate.ToString("yyyy-MM-dd"),
metrics);
r.Dimensions = "ga:campaign,ga:keyword,ga:adGroup,ga:source,ga:isMobile,ga:date";
r.MaxResults = 10000;
r.Filters = "ga:medium==cpc;ga:campaign!=(not set)";
while (true)
{
r.StartIndex = intStartIndex;
var dimensionOneData = r.Fetch();
dimensionOneData.ItemsPerPage = intMaxRecords;
if (dimensionOneData != null && dimensionOneData.Rows != null)
{
var enUS = new CultureInfo("en-US");
intIndexCnt++;
foreach (var lstFirst in dimensionOneData.Rows)
{
var objPPCReportData = new PpcReportData();
objPPCReportData.Campaign = lstFirst[dimensionOneData.ColumnHeaders.IndexOf(dimensionOneData.ColumnHeaders.FirstOrDefault(h => h.Name == "ga:campaign"))];
objPPCReportData.Keywords = lstFirst[dimensionOneData.ColumnHeaders.IndexOf(dimensionOneData.ColumnHeaders.FirstOrDefault(h => h.Name == "ga:keyword"))];
lstPpcReportData.Add(objPPCReportData);
}
intStartIndex = intIndexCnt * intMaxRecords + 1;
}
else break;
}
}
Only one thing is problamatic that your query length shouldn't exceed around 2000 odd characters
Is there an equivalent of right() function that I can use in jquery. I want to get records with fileextension xlsx.
new Guid(context.Documents.Where(T => T.FileName == ".xlsx").Select(T => T.ItemGuid).First().ToString());
something like
select * from document where right(filename,4) = 'xlsx'
I don't want to store the filename in a variable and later manipulate it. I want to be able to directly use it in my where condition. 'Documents' is my table name and "FileName" is a field that holds names of the file that I upload, now I need to get filter only the files that has the extension 'xlsx'. I tried doing
guid temp = new Guid(context.Documents.Where(T => T.FileName.Substring(T.FileName.Length - 4) == ".xlsm").Select(T => T.ItemGuid).First().ToString());
but I get the error "Sequence contains no elements" error.
* Update: Used the EndsWith() to get the information I wanted. This works now:
guid temp = new Guid(context.Documents.Where(T => T.FileName.EndsWith("xlsm")).Select(T => T.ItemGuid).First().ToString());
thanks.
filename.substr(-4)
Using .substr with a negative index will return a substring from the end of the string.
You can use .slice (MDN) function, taking into account that passing a negative value into it makes it cut the string from the end. )
var test = 'filename.xslx';
if (test.slice(-4) === 'xslx') {
alert("Passed");
}
right() is the same as endswith()
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
You might be looking for [name$="value"] selector documented here.
There is not, you can use
var filename = "file.xlsx";
var extension = filename.substr(filename.length - 4);
or to get the characters after the dot, you could use:
var extension = filename.split('.').pop();
Use could javascript match() which provides regex matching.
var filename = 'somefile.xlsx';
var matches = filename.match('/\.xlsx$/i');
if (matches.length > 0) {
// you have a match
}
My query returns searched data but it does'nt search properly
in my table values are
------------------------
Help
------------------------
1 help for abcd
2 help needed before
my Hql query given below
select help from Help help where lower(help.Subject) like lower ('%'" + searchterm + "'%')
when i search for "for" it returns
------------------------
Help
------------------------
1 help for abcd
2 help needed before
I need to return only the first
1. help for abcd
ie: I need to search only the term begins with the search term
Any one please help...
This sounds Like a Word Boundary Problem. Here Is A similar question answered
Search for "whole word match" in MySQL
Sorry, I Have No Idea Why Android Wants To Capitalize All My Words.
Hello frnds i got the solution which works perfectly
at first using the query
select help from Help help
then store the list of help in
var ListofHelps
then
foreach (var item in ListofHelps)
{
if (!string.IsNullOrEmpty(searchterm))
{
var splitsearchterm = Regex.Split(searchterm, #"\s");//split search term
var splittedsubjects = Regex.Split(item.Subject.ToUpper(), #"\s"); //Subject is to be searched
var found = splittedsubjects.Where(x => x.StartsWith(searchterm.ToUpper()));
int datacount = found.Count();
if (splitsearchterm.Count() > 1 && item.Subject.ToUpper().Contains(searchterm.ToUpper()))
{
datacount = 1;
}
if (datacount > 0)
{
Helplist.Add(new HelpViewModel //Helplist is an item in HelpViewModel ie public IEnumerable<MultiSelectList> Taglists { get; set; }
{
Subject = item.Subject,
HelpId = Convert.ToInt32(item.Id),
Content = item.Content
});
}
}
else
{
Helplist.Add(new HelpViewModel
{
Subject = item.Subject,
HelpId = Convert.ToInt32(item.Id),
Content = item.Content
});
}
}
It works for me .Is there any better way to do that
I am using MVC3 and have done a search facility in my controller.I have used the model first approach , what I want to be able to allow the user to search for results that contain the given keyword(s) in the data.
If there are no matches to the search term then display an appropriate message.
If there are matching stories:
Display a message like “7 items match your search criteria: 'XXXXX'”
Any help would be much appreciated , Thanks
would it be something like this but with use of the ViewBag to display a message?.
if (!String.IsNullOrEmpty(SearchString))
News = News.Where(s => s.Headline.Count(SearchString));
}
You need to use string.Contains for partial string matching:
var matchingResults = News.Where(s => s.Headline.Contains(searchString));
int count = matchingResults.Count();
if(count == 0)
{
//no matches
}
else
{
//display message
}