#StackBounty: #algorithm #search #tree Principal variation search: how to keep track of the best move

Bounty: 150

I have a Java implementation of the Principal Variation Search algorithm. That algorithm is used for searching a game tree starting from the root node and proceeding downwards until a particular depth reached or a terminal state is reached.
It looks like this:

public final class PrincipalVariationSearchGameEngine 
        <S extends AbstractState<S, P>,
         P extends Enum<P>> 
           extends AbstractGameEngine<S, P> {

    public PrincipalVariationSearchGameEngine(
            EvaluatorFunction<S> evaluatorFunction,
            int depth) {
        super(evaluatorFunction, depth, Integer.MAX_VALUE);
    }

    @Override
    public S makePly(S state, 
                     P minimizingPlayer, 
                     P maximizingPlayer, 
                     P initialPlayer) {
        state.setDepth(depth);

        return makePlyImplTopmost(state,
                                  depth,
                                  Double.NEGATIVE_INFINITY,
                                  Double.POSITIVE_INFINITY,
                                  initialPlayer == minimizingPlayer ? -1 : 1);
    }

    /**
     * Performs the search directly under the root node denoted by 
     * {@code state].
     * 
     * @param state the root state of the game tree to search.
     * @param depth the total depth of the search.
     * @param alpha the alpha cutoff value.
     * @param beta  the beta cutoff value.
     * @param color the color. -1 for minimizing player, +1 for maximizing
     *              player.
     * @return the game board after optimal move from {@code state}.
     */
    private S makePlyImplTopmost(S state,
                                 int depth,
                                 double alpha,
                                 double beta,
                                 int color) {
        boolean firstChild = true;
        S bestState = null;
        double tentativeScore = color == -1 ?
                                Double.POSITIVE_INFINITY :
                                Double.NEGATIVE_INFINITY;

        for (S child : state.children()) {
            double score;

            if (firstChild) {
                firstChild = false;
                score = -makePlyImpl(child, 
                                     depth - 1, 
                                     -beta, 
                                     -alpha,
                                     -color);
                bestState = child;
                tentativeScore = score;
            } else {
                score = -makePlyImpl(child, 
                                     depth - 1, 
                                     -alpha - 1.0, 
                                     -alpha,
                                     -color);

                if (color == -1) {
                    if (tentativeScore > score) {
                        tentativeScore = score;
                        bestState = child;
                    }
                } else {
                    if (tentativeScore < score) {
                        tentativeScore = score;
                        bestState = child;
                    }
                }

                if (alpha < score && score < beta) {
                    score = -makePlyImpl(child, 
                                         depth - 1,
                                         -beta,
                                         -score,
                                         -color);

                    if (color == -1) {
                        if (tentativeScore > score) {
                            tentativeScore = score;
                            bestState = child;
                        }
                    } else {
                        if (tentativeScore < score) {
                            tentativeScore = score;
                            bestState = child;
                        }
                    }
                }
            }

            if (alpha < score) {
                alpha = score;
            }

            if (alpha >= beta) {
                break;
            }
        }

        return bestState;
    }

    private double makePlyImpl(S state,
                               int depth,
                               double alpha,
                               double beta,
                               int color) {
        if (state.getDepth() == 0 
                || state.checkVictory() != null
                || state.isTerminal()) {
            return color * evaluatorFunction.evaluate(state);
        }

        boolean firstChild = true;

        for (S child : state.children()) {
            double score;

            if (firstChild) {
                firstChild = false;
                score = -makePlyImpl(child, 
                                     depth - 1, 
                                     -beta, 
                                     -alpha,
                                     -color);
            } else {
                score = -makePlyImpl(child, 
                                     depth - 1, 
                                     -alpha - 1.0, 
                                     -alpha,
                                     -color);

                if (alpha < score && score < beta) {
                    score = -makePlyImpl(child, 
                                         depth - 1,
                                         -beta,
                                         -score,
                                         -color);
                }
            }

            alpha = Math.max(alpha, score);

            if (alpha >= beta) {
                break;
            }
        }

        return alpha;
    }
}

This, however, does not work since it returns suboptimal (next) moves. I believe that the culprit is this if statement:

if (color == -1) {
    if (tentativeScore > score) {
        tentativeScore = score;
        bestState = child;
    }
} else {
    if (tentativeScore < score) {
        tentativeScore = score;
        bestState = child;
    }
}


Get this bounty!!!

#StackBounty: #powershell #search #api Handling The SharePoint REST API Search Threshold Limit In powershell

Bounty: 50

We are using SharePoint Online. I would like to search in all sitecollections for the word “passport”. I make it working with the REST api in powershell. But I have now only the problem that it returns only the first 500 results. How can I iterate into all the batches of 500 results?

I found some blog posts how to that in spfx:

https://www.c-sharpcorner.com/article/handling-the-sharepoint-rest-api-search-threshold-limit-in-spfx/

This is my powershell code:

    try
{
    $searchKeyWord = "passport"

    $secpasswd = ConvertTo-SecureString "123123!" -AsPlainText -Force
    $mycreds = New-Object System.Management.Automation.PSCredential ("test@mycompany.nl", $secpasswd)

    # Connect to SharePoint Online
    $targetSite = "https://myCompany.sharepoint.com/"
    $targetSiteUri = [System.Uri]$targetSite

    Connect-PnPOnline $targetSite -Credentials $mycreds

    # Retrieve the client credentials and the related Authentication Cookies
    $context = (Get-PnPWeb).Context
    $credentials = $context.Credentials
    $authenticationCookies = $credentials.GetAuthenticationCookie($targetSiteUri, $true)

    # Set the Authentication Cookies and the Accept HTTP Header
    $webSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession
    $webSession.Cookies.SetCookies($targetSiteUri, $authenticationCookies)
    $webSession.Headers.Add("Accept", "application/json;odata=verbose")

    # Set request variables
    $apiUrl = "$targetSite" + "_api/search/query?querytext='$searchKeyWord'&rowlimit=5000"#&rowlimit=$($rowLimit)&startrow=$($startRow)" #&selectproperties='Title,Author,Path'"

    # Make the REST request
    $webRequest = Invoke-WebRequest -Uri $apiUrl -Method Get -WebSession $webSession

    # Consume the JSON result
    $jsonLibrary = $webRequest.Content | ConvertFrom-Json
    $results = $jsonLibrary.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results

    #MaxRowLimit
    Write-Host $results.Count "Results" -ForegroundColor Green

    $ResultsArray = @()

    for($i=0; $i -le $results.length-1; $i++)
    {
        $row = $results[$i]
        $obj = New-Object PSObject

        for ($j=0; $j -le $row.Cells.results.length-1; $j++)
        {
            if ($row.Cells.results[$j].Key -eq ‘Title’)
            {
                Add-Member -InputObject $obj -MemberType NoteProperty -Name Title -Value $row.Cells.results[$j].Value
            }

            if ($row.Cells.results[$j].Key -eq ‘FileExtension’)
            {
                Add-Member -InputObject $obj -MemberType NoteProperty -Name FileExtension -Value $row.Cells.results[$j].Value
            }

            if ($row.Cells.results[$j].Key -eq ‘Path’)
            {
                Add-Member -InputObject $obj -MemberType NoteProperty -Name Path -Value $row.Cells.results[$j].Value
            }

            if ($row.Cells.results[$j].Key -eq ‘OriginalPath’)
            {
                Add-Member -InputObject $obj -MemberType NoteProperty  -Name OriginalPath -Value $row.Cells.results[$j].Value
            }

            if ($row.Cells.results[$j].Key -eq ‘Author’) #
            {
                Add-Member -InputObject $obj -MemberType NoteProperty -Name Author -Value $row.Cells.results[$j].Value
            }

            if ($row.Cells.results[$j].Key -eq ‘HitHighlightedSummary’)
            {
                Add-Member -InputObject $obj -MemberType NoteProperty -Name HitHighlightedSummary -Value $row.Cells.results[$j].Value
            }

            if ($row.Cells.results[$j].Key -eq ‘SiteName’)
            {
                Add-Member -InputObject $obj -MemberType NoteProperty -Name SiteName -Value $row.Cells.results[$j].Value
            }

            if ($row.Cells.results[$j].Key -eq ‘SPWebUrl’)
            {
                Add-Member -InputObject $obj -MemberType NoteProperty -Name SPWebUrl -Value $row.Cells.results[$j].Value
            }

            if ($row.Cells.results[$j].Key -eq ‘IsDocument’)
            {
                Add-Member -InputObject $obj -MemberType NoteProperty -Name IsDocument -Value $row.Cells.results[$j].Value
            }

            if ($row.Cells.results[$j].Key -eq ‘ParentLink’)
            {
                Add-Member -InputObject $obj -MemberType NoteProperty -Name ParentLink -Value $row.Cells.results[$j].Value
            }

            if ($row.Cells.results[$j].Key -eq ‘ViewsLifeTime’) # aantal hits, niet unieke hits
            {
                Add-Member -InputObject $obj -MemberType NoteProperty -Name ViewsLifeTime -Value $row.Cells.results[$j].Value
            }

            if ($row.Cells.results[$j].Key -eq ‘ViewsRecent’) #
            {
                Add-Member -InputObject $obj -MemberType NoteProperty -Name ViewsRecent -Value $row.Cells.results[$j].Value
            }

            if ($row.Cells.results[$j].Key -eq ‘Rank’) #
            {
                Add-Member -InputObject $obj -MemberType NoteProperty -Name Rank -Value $row.Cells.results[$j].Value
            }
        }

        $ResultsArray += $obj
    }

    $ResultsArray | Export-Csv -Path "c:outfile.csv" -NoTypeInformation
}
catch
{
    Write-Host $_.Exception.Message -ForegroundColor Red
}

Write-Host "Finished" -ForegroundColor Green


Get this bounty!!!

#StackBounty: #regular-expression #search #highlight Highlighting a search capture group

Bounty: 50

By :set hl, the search result of a / expression is highlighted, for example:

Vim search highlight in action

And if one wants to replace one substring distinguished by its surrounding, one can do so elegantly using regex capture groups:

replace not with and

However, the search highlight does not reflect this capture group. Sometimes, it would be very helpful if it did, so you can feel more confident about your attempted regex. Does Vim have such a feature?


Get this bounty!!!

#StackBounty: #search #apache-solr Solr query for terms closely and frequently used with another term

Bounty: 50

We are attempting to find terms (actually words) that most frequently appear in some proximity to a given term.

When using facetting like this:
?q=myfield:tree&facet=on&facet.query=tree&facet.field=myfield it appears we are getting the counts for the most-occuring words in myfield, next to tree.

Question: However, we would like to kind of sub-facette the query, including the distances for each term (or an average distance).

The myfield-field is stored, tokenized, the termvectors are stored and offset and position are stored with the termvector.


Get this bounty!!!

#StackBounty: #custom-taxonomy #search WordPress Search – display taxonomy terms in results

Bounty: 50

I have a custom post type of Hotel. Hotels can be can be categorised with the taxonomy Resort.

On my search page I need to be able to list hotels and taxonomy terms in the results, as separate results. eg:

Resort Name
Hotel Name
Hotel Name
Hotel Name

Resorts should come first, followed by hotels and anything else. As far as I know taxonomy terms are not shown by default in WordPress search.

In my functions.php I’m currently limiting the search to specific post types:

function filter_search($query) {
// Don't run in admin area
if(!is_admin()) {
    // Limit search to posts
    if($query->is_main_query() && $query->is_search()) {
        $query->set('post_type', array('hotel', 'post', 'activities', 'page'));
    }

    // Return query
    return $query;
  }
}

add_filter('pre_get_posts', 'filter_search');

Then in my search.php I am grouping the results by post type:

<?php $types = array('hotel', 'post', 'activities', 'page');
foreach( $types as $type ){

echo '
'; ?>

Hotel: Activity: Blog Post: Page: Page: ">

" class="button">View Page

</div> <?php } } rewind_posts(); echo '</div> '; } ?>

What I’m struggling with is how to tell WordPress to show the taxonomy term (Resort) in the results as it’s own result. Can anybody help?


Get this bounty!!!

#StackBounty: #2010 #search #document-id No documents with the ID xxx were found in this site collection

Bounty: 50

I have the following situation on our SharePoint 2010 environment.
Sometimes it happens, that a document id link of a document in a library does not work anymore.
When you click on the link it says this error:

Operation Completed Successfully

No documents with the ID PRODUCTS-xxx-xxx were found in this site
collection.

enter image description here

The document is not being changed and even when an incremental or full crawl ran, the document id link is still not working.

This is happening in one specific document library of a site collection. Other document libraries in the site collection does not have this issue.

I already tried the solutions in this post, but these did not help either.

SP2010 – After upload Doc ID is assigned, but using the Doc ID link results in No documents with the ID where found in this site collection

Any ideas why this happens and what I can do in this situation to make the link work again?


Get this bounty!!!

#StackBounty: #google-search #search #google-groups #keyword #usenet How to search Google Groups for keywords

Bounty: 100

I went to https://groups.google.com and searched for boot ring seat, looking for a specific Usenet message that I know has those three words in it. No results. All right, I thought, maybe I’m misremembering the Usenet message. So I searched instead for whenever — there must be some Usenet messages with that word in it! But still no results. (It says “Posts: 0, groups: 1354”.) (These searches were done when not logged in to Google.)

What am I doing wrong? How do I search for Usenet posts by keywords in them?


Some notes (that you can skip) about research I already did toward answering this question:

There is a help link on that search-result page, but there’s nothing about searching listed there. The most promising subtopic is “Learn how to read and create posts”, which doesn’t actually answer this question.

I also did a Google Web search on searching google groups usenet, but the top few results were unhelpful. The top one is from 2010, so I skipped it as likely OBE; the next promising one is this SU post, which is about browsing a newsgroup rather than searching by keyword; etc.


Get this bounty!!!

#StackBounty: #8 #search Filter by tags in search api views?

Bounty: 50

I’m working to create a search API view. I have on exposed filter that’s “fulltext search”. I’d like to expose another filter that works similar to the core exposed entity reference, in that my users can reference multiple tags, seperated by commas, and the field will autocomplete the results for each item.

Is there a way to do this using the search api views module and the search api autocomplete module? AFAICT there’s not a way to autocomplete multiple words/phrases, instead of just the first word/phrase.


Get this bounty!!!

#StackBounty: #python #search #grid #knn #imputation grid search with own estimator in python

Bounty: 50

I am trying to build my own estimator (regressor) and use it for imputation (KnnImputation).
For now – I wrote a very basic knn imputation, when it will work I will change the algorithm a bit.

I’m having a problem using the grid search “GridSearchCV”.
I tried to print the shapes of the data to get a sense of the problem. When the configuration is 10-fold cross validation I would expect the prints to be 10 times this lines:

xTrain size : 2487
yTrain size : 2487
test size : 276

But instead I get this lines:

xTrain size : 2487
yTrain size : 2487
test size : 276

test size : 2487

more the 60 times.

Any idea what is the problem?

My Code:

class KnnImputation(BaseEstimator, RegressorMixin):

    def __init__(self, k=5, distance='euclidean'):
        self.k = k
        self.distance = distance

    def get_params(self, deep=False):
        return {'k': self.k, 'distance': self.distance}

    def set_params(self, **parameters):
        self.k = parameters['k']
        self.distance = parameters['distance']

    def fit(self, X, y):
        self.xTrain = X.values
        self.yTrain = y.values
        print("nxTrain size : " + str(self.xTrain.shape[0]))
        print("yTrain size : " + str(self.yTrain.shape[0]))

        return self

    def predict(self, xTest):
        xTest = xTest.values
        num_test = xTest.shape[0]
        print("test size : " + str(num_test)+"n")
        yPred = np.zeros(num_test, dtype=self.yTrain.dtype).reshape(-1, 1)

        for i in range(num_test):
            distances = np.sum(np.abs(self.xTrain - xTest[i, :]), axis=1)
            idx = np.argsort(distances)
            minIndexes = idx[:self.k]
            kClosest = self.yTrain[minIndexes[:]]
            yPred[i] = np.mean(kClosest)

        return yPred

kf = KFold(n_splits=10, shuffle=False, random_state=23)
NN = KnnImputation()
gridSearchNN = GridSearchCV(NN, param_grid=params, scoring="neg_mean_squared_error", n_jobs=1,
                                cv=kf.split(xTrain, yTrain), verbose=1)
gridSearchNN.fit(X=xTrain, y=yTrain)

The Error:

  File "C:Users....dataImputation.py", line 85, in knnImputationMethod
    gridSearchNN.fit(X=xTrain, y=yTrain)
  File "C:Users...Anaconda3libsite-packagessklearnmodel_selection_search.py", line 740, in fit
    self.best_estimator_.fit(X, y, **fit_params)
AttributeError: 'NoneType' object has no attribute 'fit'


Get this bounty!!!