we have a TYPO3 project and use SOLR as search engine. i'm wondering how does a if-statement/conditional look like in the config files written in TypoScript?
TYPO3: 8.7
Apache Solr for TYPO3 - ES: 7.5.3
for example: we use
plugin.tx_solr.search.query.sortBy = data_datax_title_stringS asc
as sort setting for the following facet block:
plugin.tx_solr.search.faceting.facets {
but we only want that sorting if a certain part of the url query string is empty (q= or q=Searchtext)
so the sortBy should be applied if the query string looks like
http://localhost/?tx_solr%5Bq%5D=&L=0&id=2883
and should not be applied on
http://localhost/?tx_solr%5Bq%5D=Searchtext&L=0&id=2883
here is the actual block:
[globalVar = TSFE:id={$site.config.search_page_blasts}]
plugin.tx_solr.search.targetPage = {$site.config.search_page_blasts}
config.defaultGetVars {
tx_solr.filter.0 = result_type_filter:blast
}
plugin.tx_solr.search.query.sortBy = dynamic_field_A_stringS asc
plugin.tx_solr.search.faceting.facets {
facetX < lib.solr.facets.directBlast
facetX.field = dynamic_field_X_boolS
}
any help is highly appreciated
edit:
i found
plugin.tx_solr.search.query.getParameter = q
but this only defines the name for the query get-parameter in case another service needs a specific name. but i would need the value of this parameter and condition the sortBy by its value.
edit:
after some research im now at this state: the sort works if a query string is set - but not if its empty
[globalVar = GP:q = ""]
plugin.tx_solr.search.query.sortBy = wine_winery_title_stringS asc
[else]
plugin.tx_solr.search.query.sortBy =
[end]
[globalVar = TSFE:id={$site.config.search_page_wineries}]
plugin.tx_solr.search.targetPage = {$site.config.search_page_wineries}
config.defaultGetVars {
tx_solr.filter.0 = result_type_filter:winery
}
plugin.tx_solr.search.faceting.facets {
direct_sale < lib.solr.facets.directSale
direct_sale.field = winery_direct_sale_boolS
i dont really know how to format this the right way - nested conditions are not supported right?
We had a similiar use case and could not find a solution with existing featureset, so we ended up using a userfunction to check and redirect using the correct parameters.
Imo this is not the best way it should be solved though, so I am curious about other proposals.
# default sort by wine_winery_title_stringS
page.1558101700 = USER_INT
page.1558101700.userFunc = VENDOR\MyExt\UserFuncs\Solr->applyDefaultSorting
the userfunc could look like this:
/**
* #return void
*/
public function applyDefaultSorting()
{
$requestUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
$solrParameters = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tx_solr');
$additionalParameterCharacter = '?';
if(strpos($requestUrl, '?') !== false){
$additionalParameterCharacter = '&';
}
// todo: get solr search parameter name from settings
if(isset($solrParameters['q']) === false || empty($solrParameters['q'])){
$redirectUri = $requestUrl . $additionalParameterCharacter . 'tx_solr[sort]=wine_winery_title_stringS+asc';
header('Location: '.$redirectUri);
}
}
hope it helps
[globalVar = GP:q = ""]
plugin.tx_solr.search.query.sortBy = wine_winery_title_stringS asc
[else]
plugin.tx_solr.search.query.sortBy =
[end]
but with [globalString = GP:q = /^$/]?
i ended up extending the outer condition and just having two blocks for that page - i feels redundant but works perfectly fine. the condition outside of the existing one was not working - and nested conditions are not possible. so here is the solution:
with globalString to use regex for comparison
[globalVar = TSFE:id={$site.config.search_page_x}] && [globalString = GP:tx_solr|q = /.+/]
and globalVar for an empty parameter
[globalVar = TSFE:id={$site.config.search_page_x}] && [globalVar = GP:tx_solr|q =]
hope i can save someone a little time researching - thanks to everyone for their input
Related
I am using Sitecore Solr search for searching using a keyword string, Is there a way to know the number of matches for each of the returned result items?.
The following is the code I am using:
using (var context = Index.CreateSearchContext())
{
List<Item> ResultList = new List<Item>();
var contentPredicate = PredicateBuilder.True<customSearchResultItem>();
contentPredicate = contentPredicate.And(p => p.Content.Contains(SearchKey));
contentPredicate = contentPredicate.And(p => p.Name != "__Standard Values");
var languagePredicate = PredicateBuilder.True<customSearchResultItem>();
languagePredicate = languagePredicate.And(p => p.Language == Context.Language.Name);
var CombinPredicates = PredicateBuilder.True<customSearchResultItem>();
CombinPredicates = CombinPredicates.And(languagePredicate);
CombinPredicates = CombinPredicates.And(contentPredicate);
// execute the search
IQueryable<customSearchResultItem> query = context.GetQueryable<customSearchResultItem>().Where(CombinPredicates);
var hits = query.GetResults().Hits;
}
From what I know, you can not get the number of matches for every result item based on the keyword used for search. What you can get, is a score value from Solr.
var hits = query.GetResults().Hits;
foreach (var hit in hits)
{
var score = hit.Score;
}
This is the value for the whole query, so it includes all predicates like language, not Standard Values and keywords in your case.
Remember, that this value can be different if you use Solr and if you use Lucene - this is dependent on the internal calculations.
I solved this by adding boosting values to each predicate then the for each result item I got the score and divide it by .59 which in my case the maximum value that occurs when all predicates staesfied; The code in details can be found on the following blog post:
http://sitecoreinfo.blogspot.com/2015/10/sitecore-solr-search-result-items.html
I am trying to use a cursor with Objectify and Google App Engine to return a subset of data and a cursor so that I can retrieve more data when the user is ready. I found an example here that looks exactly like what I need but I don't know how to return the final list plus the cursor. Here is the code I have:
#ApiMethod(name = "listIconThemeCursor") //https://code.google.com/p/objectify-appengine/wiki/Queries#Cursors
public CollectionResponse<IconTheme> listIconThemeCursor(#Named("cursor") String cursorStr) {
Query<IconTheme> query = ofy().load().type(IconTheme.class).limit(10);
if (cursorStr != null ) {
query.startAt(Cursor.fromWebSafeString(cursorStr));
}
List<IconTheme> result = new ArrayList<IconTheme>();
int count = 0;
QueryResultIterator<IconTheme> iterator = query.iterator();
while (iterator.hasNext()) {
IconTheme theme = iterator.next();
result.add(theme);
count++;
}
Cursor cursor = iterator.getCursor();
String encodeCursor = cursor.toWebSafeString();
return serial(tClass, result, encodeCursor);
}
Note that this was modified from a previous endpoint in which I returned the CollectionResponse of ALL the data. My dataset is large enough that this is no longer practical. Basically, I don't know what was in the user's function of 'serial(tClass, result, encodeCursor) that let it get returned to the user.
There is another example here but it doesn't appear to answer my question either.
I don't quite understand what you are asking, but I see one immediate bug in your code:
query.startAt(Cursor.fromWebSafeString(cursorStr));
...should be:
query = query.startAt(Cursor.fromWebSafeString(cursorStr));
Objectify command objects are immutable, functional objects.
After a long slog, I figured out that CollectionResponse has the cursor in it :(
Here is the complete code I used incorporating the comment from stickfigure above:
#ApiMethod(name = "listIconThemeCursor", path="get_cursor")
public CollectionResponse<IconTheme> listIconThemeCursor(#Named("cursor") String cursorStr) {
Query<IconTheme> query = ofy().load().type(IconTheme.class)
.filter("errors <", 10)
.limit(10);
if (cursorStr != null ) {
query = query.startAt(Cursor.fromWebSafeString(cursorStr));
}
List<IconTheme> result = new ArrayList<IconTheme>();
QueryResultIterator<IconTheme> iterator = query.iterator();
while (iterator.hasNext()) {
IconTheme theme = iterator.next();
result.add(theme);
}
Cursor cursor = iterator.getCursor();
CollectionResponse<IconTheme> response = CollectionResponse.<IconTheme> builder()
.setItems(result)
.setNextPageToken(cursor.toWebSafeString())
.build();
return response;
}
How to map the OLE DB source SQL command query parameters with variables using EzAPI ?
Basically I need to do something like below.
Thanks in advance.
Here is how I had to do it for SSIS 2012. I had to find the GUID of the variable in question and set it that way.
EzOleDbSource source = new EzOleDbSource(this);
source.Connection = sourceconnection;
source.SqlCommand = sourcecomannd;
source.AccessMode = AccessMode.AM_SQLCOMMAND;
source.SetComponentProperty("ParameterMapping", "\"Parameter0:Input\",{C2BCD5B0-1FDB-4A74-8418-EEF9C1D19AC3};");
To get the GUID you can query the Variables in the EZPackage object.
Application a = new Application();
var package = a.LoadPackage(packagelocation, null);
var ezpackage = new EzPackage(package);
var firstOrDefault = ezpackage.Variables.OfType<Microsoft.SqlServer.Dts.Runtime.Variable>()
.AsQueryable()
.FirstOrDefault(x => x.Name.Equals("MyParameter"));
if (firstOrDefault != null)
{
var guid =
firstOrDefault.ID;
}
I have accepted Geek's answer because it is the real answer for my question. But I found instead of mapping variables to parameters we can use variables directly in the query. For example: exec your_sp_name "#[User::your_variable_name]"
UPDATE : Above method is not working.
Use the the accepted answer method. To take the GUID of the variable, I used the follwing method.
string guid = string.Empty;
foreach (var x in this.Variables)
{
if (x.Name == "cdc_capture_log_id")
{
guid = x.ID;
}
}
Where this = EzPackage. Same as above.
How can I filter properly using Objectify 4 by several parameters, considering that some of those parameters can come empty, which would mean that I don't want to filter by those?
Example:
Please consider I want to filter something like this:
releases = ofy().load().type(Release.class)
.filter("user.name", searchCriteria.getName())
.filter("category", searchCriteria.getCategory())
.filter("city", searchCriteria.getCity()).list();
In order to match with what I said above, I have now the following code, checking every time which of my parameters come empty so I don't put them on the filter in that case:
if (!nameEmpty && !categoryEmpty && !cityEmpty) {
releases = ofy().load().type(Release.class)
.filter("user.name", searchCriteria.getName())
.filter("category", searchCriteria.getCategory())
.filter("city", searchCriteria.getCity()).list();
} else if (!nameEmpty && !categoryEmpty) {
releases = ofy().load().type(Release.class)
.filter("user.name", searchCriteria.getName())
.filter("category", searchCriteria.getCategory()).list();
} else if (!nameEmpty && !cityEmpty) {
releases = ofy().load().type(Release.class)
.filter("user.name", searchCriteria.getName())
.filter("city", searchCriteria.getCity()).list();
} else if ...
...
How can I avoid this crappy way of filtering and make it with just one line (or a few) using Objectify 4?
Query<Release> query = ofy().load().type(Release.class);
if (!nameEmpty)
query = query.filter("user.name", searchCriteria.getName());
if (!categoryEmpty)
query = query.filter("category", searchCriteria.getCategory())
if (!cityEmpty)
query = query.filter("city", searchCriteria.getCity());
releases = query.list();
I been trying to get sqlcachedependecy working, but it doesn't appear to work
I got the proper settings in my web.config and also global.asa, however when I run this query and the changes are made to the database from either with in or outside the web site the cached objects are not updated please someone help? I know its not because this query is querying a view, because I tested this using straight SqlDependecy and the notification works fine.
public IQueryable<VictoryList> GetVictoryList()
{
string cacheKey = HttpContext.Current.User.Identity.Name + "victoryCacheKey";
IQueryable<VictoryList> cachednews = (IQueryable<VictoryList>)HttpContext.Current.Cache.Get(cacheKey);
if (cachednews == null)
{
var results = from v in _datacontext.ViewVictoryLists
orderby _datacontext.GetNewId()
select new VictoryList
{
MemberID = v.MemberID,
Username = v.Aspnetusername,
Location = v.Location,
DaimokuGoal = v.DaimokuGoal,
PreviewImageID = v.PreviewImageID,
TotalDaimoku = v.TotalDaimoku,
TotalDeterminations = v.TotalDeterminations,
DeterminationID = v.DeterminationID,
DeterminationName = v.DeterminationName
};
results = results.ToList().AsQueryable();
SqlCacheDependencyAdmin.EnableNotifications(_datacontext.Connection.ConnectionString);
SqlCacheDependency dependency =
new SqlCacheDependency(_datacontext.GetCommand(results) as SqlCommand);
HttpContext.Current.Cache.Insert(cacheKey, results, dependency);
return results;
}
return cachednews;
}
According to the stated Limitations for creating a query for notification, listed at msdn...
The statement must not reference a view.