小编ar0*_*968的帖子

Elasticsearch:按查询删除在很多要删除的文档上确实很慢

我正在使用按查询插件删除进行弹性搜索。

我有一个products带有整数字段的索引size。我想删除大小为 10 的所有文档。我有超过 5000 个大小为 10 的文档。如果我尝试:

DELETE /products/product/_query?q=size:10
Run Code Online (Sandbox Code Playgroud)

此查询需要超过 2 分钟。

delete by query文档中了解到,因为插件很慢:

在内部,它使用 Scroll 和 Bulk API 以高效且安全的方式删除文档。它更慢[..] 匹配大量文档的查询可能会运行很长时间,因为每个文档都必须单独删除。

如何执行最快的文档批量删除?

elasticsearch

5
推荐指数
1
解决办法
4495
查看次数

Typescript:重写某些方法时强制调用 super

BaseComponent我有一个带有方法的基类,我希望所有扩展我的方法并重写该方法的foo()类始终调用超级方法:BaseComponentfoo()

export class BaseComponent {
    foo(){}
}

export class ExtendedComponent extends BaseComponent  {

    constructor(){
        super();
    }

    // BAD
    foo(){
    }

    // GOOD
    foo(){
       super.foo();
    }
}
Run Code Online (Sandbox Code Playgroud)

Typescript 中的一些技巧?

typescript

5
推荐指数
1
解决办法
3753
查看次数

Delphi SOAP:在调度响应后删除临时文件

我有一个肥皂方法,即时创建和回复PDF内容.

在方法上finally,临时pdf文件被删除.

这是finally执行此操作的正确位置?

procedure TWbModule.WbModuleGetPDFAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
    aPDFFileTemp : string;
begin
    try
        // getTempPdf() creates and returns the PDF path, eg.: C:\files\foo.pdf
        aPDFFileTemp := getTempPdf();

        // set response content stream with file stream
        Response.ContentStream := TFileStream.Create(aPDFFileTemp, fmOpenRead or fmShareDenyNone);
        Response.ContentType   := 'application/pdf';
    finally
        // delete temporary file
        // It is the right place for perform this operation?
        if FileExists(aPDFFileTemp) then DeleteFile(aPDFFileTemp );
    end;
end;
Run Code Online (Sandbox Code Playgroud)

delphi soap

4
推荐指数
1
解决办法
308
查看次数

Delphi:TStringList中的搜索字符串

我有一个大的txt(ipaddress.txt),有很多行,每行是一个IP地址,例如:

44.XXX.XXX.XXX
45.XXX.XXX.XXX
46.XXX.XXX.XXX
47.XXX.XXX.XXX
48.XXX.XXX.XXX
Run Code Online (Sandbox Code Playgroud)

我加载此列表TStringList,例如:

FIpAddressList := TStringList.Create();
FIpAddressList.Sorted := true;
FIpAddressList.LoadFromFile('ipaddress.txt');
Run Code Online (Sandbox Code Playgroud)

我想检查列表中是否有IP地址,例如:

function IsIPinList(const IPAddress : string): Boolean;
begin
   Result := (FIpAddressList.IndexOf(IPAddress) <> -1);
end;
Run Code Online (Sandbox Code Playgroud)

它有效......但是速度很慢TStringList.

有没有办法让这个过程更快?

UPDATE

  • 该列表是静态的,每月更新一次,少于或多于5,000行.
  • 在服务器上的每个请求处调用该函数(例如,每秒5次).
  • 仅在服务器服务启动时加载该列表.

delphi

4
推荐指数
1
解决办法
1734
查看次数

在企业防火墙后面使用create-react-app

create-react-app通过设置代理,有任何方法可以在公司防火墙后面工作.

我已经在npm和yarn上设置了代理,但这是我在尝试时看到的create-react-app my-app:

Creating a new React app in F:\react\my-app.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...

You appear to be offline.
Falling back to the local Yarn cache.

yarn add v0.23.4
info No lockfile found.
[1/4] Resolving packages...
error Couldn't find any versions for "react" that matches "latest" in our cache. Possible versions: ""
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

Aborting installation.
  yarnpkg add --exact --offline react …
Run Code Online (Sandbox Code Playgroud)

node.js reactjs

4
推荐指数
4
解决办法
4748
查看次数

javascript:在模块内部使用strict是不必要的

tsling引发错误:

第1行:模块内部不需要'use strict'(严格)

这是我的代码

"use strict";

function Foo() {}

Foo.prototype.sayHello= function () {
    console.log("hello!");
}

if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
    module.exports = { 
        Foo: Foo
    };
}
Run Code Online (Sandbox Code Playgroud)

怎么修复这个错误?

边注

我的代码同时使用module和vanilla javascript.我只想"strict mode"用于香草javascript.

也许我可以使用

if (typeof module !== 'undefined') {
    "use strict";
}
Run Code Online (Sandbox Code Playgroud)

strict mode仅启用vanilla javascript?

javascript

4
推荐指数
2
解决办法
2767
查看次数

rxjs Observable:处理所有订阅的取消订阅

我有一个返回 Observable 的方法

subFoo(id): Observable<number> {
    return new Observable<number>(observer => {
        setTimeout(() => {
            observer.next(id);
        }, 1000);
    });
}
Run Code Online (Sandbox Code Playgroud)

现在我订阅了三次,5秒后全部取消订阅:

const sub1 = subFoo(1).subscribe(result => console.log(result));
const sub2 = subFoo(2).subscribe(result => console.log(result));
const sub3 = subFoo(3).subscribe(result => console.log(result));

setTimeout(() => {
  sub1.unsubscribe();
  sub2.unsubscribe();
  sub3.unsubscribe();
}, 5000);
Run Code Online (Sandbox Code Playgroud)

我可以处理所有听众的完全取消订阅吗?

例如。(伪代码):

subFoo(id): Observable<number> {
    return new Observable<number>(observer => {

        // something like this
        observer.onAllListenerAreUnsubscribed(() => {
           console.log('All Listener Are Unsubscribed!');
        });

        setTimeout(() => {
            observer.next(id);
        }, 1000);
    });
}
Run Code Online (Sandbox Code Playgroud)

现场演示:https ://stackblitz.com/edit/angular-ayl12r

javascript rxjs

4
推荐指数
1
解决办法
5370
查看次数

角材料:错误“没有MatChip提供程序”

我想在组件中使用芯片

my-comp.module.html

<mat-form-field class="example-chip-list" #chipList>
      <mat-chip-list>
        <mat-chip *ngFor="let role of user.roles" [selectable]="selectable"
        [removable]="removable"
        (removed)="remove(role)">{{ role.name }}</mat-chip>
        <mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
        <input
          placeholder="New fruit..."
          #fruitInput
          [formControl]="fruitCtrl"
          [matAutocomplete]="auto"
          [matChipInputFor]="chipList"
          [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
          [matChipInputAddOnBlur]="addOnBlur"
          (matChipInputTokenEnd)="add($event)">
      </mat-chip-list>
    </mat-form-field>
Run Code Online (Sandbox Code Playgroud)

my-comp.module.ts

@NgModule({
  declarations: [MyComp],
  imports: [
    CommonModule,
    MatButtonModule,
    MatIconModule,
    FlexLayoutModule,
    FormsModule,
    ReactiveFormsModule,
    MatFormFieldModule,
    MatInputModule,
    MatChipsModule,
    MatAutocompleteModule
  ],
  exports: [MyComp]
})
export class MyCompModule { }
Run Code Online (Sandbox Code Playgroud)

但这会引发错误:

error-handler.service.ts:11 Error: StaticInjectorError(AppModule)[MatChipRemove -> MatChip]: 
  StaticInjectorError(Platform: core)[MatChipRemove -> MatChip]: 
    NullInjectorError: No provider for MatChip!
    at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:717)
    at resolveToken (core.js:954)
    at tryResolveToken (core.js:898) …
Run Code Online (Sandbox Code Playgroud)

angular-material angular

4
推荐指数
1
解决办法
402
查看次数

pdfjs:使用正确的换行符/带空格从 pdf 获取原始文本

使用pdf.js,我做了一个简单的函数来从 pdf 中提取原始文本:

async getPdfText(path){

    const pdf = await PDFJS.getDocument(path);

    const pagePromises = [];
    for (let j = 1; j <= pdf.numPages; j++) {
        const page = pdf.getPage(j);

        pagePromises.push(page.then((page) => {
            const textContent = page.getTextContent();
            return textContent.then((text) => {
                return text.items.map((s) =>  s.str).join('');
            });
        }));
    }

    const texts = await Promise.all(pagePromises);
    return texts.join('');
}

// usage
getPdfText("C:\\my.pdf").then((text) => { console.log(text); });
Run Code Online (Sandbox Code Playgroud)

但是我找不到正确提取新行的方法,所有文本仅在一行中提取。

如何正确提取文本?我想以与台式电脑相同的方式提取文本:

打开pdf(双击文件)-> 选择所有文本(CTRL + A)-> 复制所选文本(CTRL + C)-> 粘贴复制的文本(CTRL + V)

javascript pdf pdfjs

4
推荐指数
1
解决办法
710
查看次数

Angular:禁用带有指令的材质按钮不起作用

我想通过指令禁用一些按钮(向按钮添加禁用属性)。

该指令适用于经典的 html 按钮,但不适用于有角度的材料设计按钮(mat-button)

import { Component, Directive, ElementRef, Renderer2 } from '@angular/core';


@Directive({
  selector: '[myDisableButton]'
})
export class HideCantEditDirective {
  constructor(private el: ElementRef, private renderer: Renderer2) {
    // try with Renderer2
    this.renderer.setProperty(this.el.nativeElement, 'disabled', true);
    // try with ElementRef
    this.el.nativeElement.disabled = true;

    this.renderer.setStyle(this.el.nativeElement, 'border', '2px solid green');
  }
}



@Component({
  selector: 'my-app',
  template: `
  <button mat-button myDisableButton (click)="onClick()">Material Button</button><br /><br />
  <button myDisableButton (click)="onClick()">Classic Button</button>`,
  styles: [ 'button:disabled { border: 2px solid red !important; }' ]
})
export …
Run Code Online (Sandbox Code Playgroud)

javascript typescript angular-material angular

4
推荐指数
1
解决办法
1367
查看次数